JavaScript Function Tutorial

This JavaScript tutorial will demonstrate the role of the JavaScript function, how event handlers are used to call the JavaScript function and values which can be passed as parameters to the JavaScript function.

Prepare to be greeted twice

Code Example
  1. // variables are declared outside a function
  2. var name1 = "Fred";
  3. var name2 = "Wilma";
  4. function greet(who) {
  5. alert("Greetings " + who);
  6. alert("Greetings " + name2);
  7. name2 ="Jack";
  8. // declare name2 with var in the above line to change the name2 variable to a global variable, which displays Wilma rather than Jack on the second turn.
  9. }