Javascript Functions: Did You Know...?
Here are some handy tips on Javascript functions from W3Cschools.com
- To keep the browser from executing a script when the page loads, you can put your script into a function.
- A function contains code that will be executed by an event or by a call to the function.
- You may call a function from anywhere within a page (or even from other pages if the function is embedded in an external .js file).
- Functions can be defined both in the <head> and in the <body> section of a document.
- However, to assure that a function is read/loaded by the browser before it is called, it could be wise to put functions in the <head> section.
Two Javascript Functions: Check It Out!
The messages that appear in red below were created with a script that includes two functions: The first function writes a message to the screen using an argument that will be passed to it from a calling statement; the second function displays a message that is defined within the function itself.