Local JavaScript Variables
A variable declared (using var) within a JavaScript function becomes LOCAL
and can only be accessed from within that function. (the variable has local
scope).You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared.
Local variables are deleted as soon as the function is completed.
Global JavaScript Variables
Variables declared outside a function, become GLOBAL, and all scripts and functions on the web page can access it.The Lifetime of JavaScript Variables
The lifetime JavaScript variables starts when they are declared.Local variables are deleted when the function is completed.
Global variables are deleted when you close the page.
Assigning Values to Undeclared JavaScript Variables
If you assign a value to variable that has not yet been declared, the variable will automatically be declared as a GLOBAL variable.This statement:
carname="Volvo";
No comments: