Google

variables

Variables are containers that hold data such as numbers and strings.
Variable names consist of any number of letters ,  underscore and digits. The first letter must be a letter or an underscore.
Variable names are case sensitive; e.g., Name, name, and NAme are all different variable names.

Declaring and Initializing Variables

Variables must be declared before they can be used. There are two ways to declare a variable: either explicitly preceded by the keyword var, or not.  it is a better practice to always use the var keyword.  You can assign a value to the variable (or initialize a variable) when you declare it, but it is not mandatory, unless you omit the var keyword. If a variable is declared but not initialized, it is "undefined."


Scope of Variables

Scope describes where a variable is visible, or where it can be used, within the program. JavaScript variables are either of global or local scope. A global variable can be accessed from any JavaScript script on a page .

Local variables are created when a variable is declared within a function. Local variables must be declared with the keyword, var. They are accessible only from within the function from the time of declaration to the end of the enclosing block, and they take precedence over any global variable with the same name .

No comments: