Monday, September 28, 2015

SOFT6008 Initialising variables

Code that is in a function inside the head is executed only when the function is called.

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: