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
// variables are declared outside a function
var name1 = "Fred";
var name2 = "Wilma";
function greet(who) {
alert("Greetings " + who);
alert("Greetings " + name2);
name2 ="Jack";
// 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.