Code that is in the head but not in a function is executed once before the page loads. So you can initialise variables this way. But you cannot modify the DOM in there because it doesn't exist yet.
Code that is in the body is executed once as the page is loaded.
So the money variable can be initialised in the body or in the head (outside the function). But it can only be displayed on the page inside the function.
No comments:
Post a Comment