After the call to shuffle is completed, the execution returns to the call site (the place where the function was called).
If the call site was right before the top-level call to renderSongs(sortSongs()) then yes, that second call would “undo” the call to renderSongs(sortSongs()) called from inside shuffle.
shuffle();
renderSongs(sortSongs());
But that isn’t what happens.
renderSongs(sortSongs()) is called one time on the initial code execution (to render the song list) and after that all subsequent calls to it happens inside event handlers to re-render the list after it has been update (song deleted, list shuffled).
If you look at the final code you can better see it, the code might look broken on different steps before the app is completed, if the execution order isn’t in its final stage.
Ah, I see now! I’m really sorry for the confusion. As a beginner, I knew that the computer reads the code from top to bottom, so I always thought that whenever something happens, the computer reads it again from top to bottom. That’s why I thought the renderSongs() function was called every time a change was made. Thank you for explaining. Now I understand that the reading occurs only once.
It’s like the computer reads and remembers everything initially, and then when the user interacts, it picks up the functions and variables it remembered from the first reading, stores them into the variables we set, and repeats this process. Please correct me if I’m wrong.