HTML and CSS Reference
var variable_name = value; // initialized
To declare a variable called firstname , you could say
You can declare multiple variables on the same line by separating each declaration
with a comma. For example, you could say
var first_name, middle_name, last_name;
<head><title>Using the var Keyword</title>
var language="English" ;
// Variable is initialized
var name ;
// OK, undefined variable
// Not OK! var keyword missing ERROR!
document.write("Language is " + language + "<br />");
document.write("Name is "+ name + "<br />");
document.write("Age is "+ age + "<br />");
The variable called language is defined and initialized. The var keyword is not re-
quired here, but is recommended.
Because the variable called name is not initialized, the var keyword is required here.