@laura In both cases, you have a function defined, which then needs to be called to start off the animation. At the end of the function, you have a requestAnimationFrame(function) call, which causes the function to run again, and again, and again … etc.
In the first example, the animation chain is started by simply calling loop() at the end of the code. In the second example, draw() is called via an event listener:
image.onload = draw;
So the animation only starts running once the image that it relies on is loaded into memory and available to use.