Javascript is non-typed, which means that its variables can store any type of values. It can be converted quickly and automatically if necessary.
Variable Declaration uses var. a var statement can declare multiple variables and separate them with commas. It can also bind the variable declaration with the variable initialization.
Repeated declaration and missing Declaration: var multiple declarations of the same variable are legal. An error occurs when you try to read the value of an undeclared variable. If you assign a value to a variable that is not declared by VAR, JavaScript will implicitly declare the variable, however, variables declared implicitly are always created as global variables. Therefore, we recommend that you use the VaR statement to create global or local variables. For example:
Scope = "Global"; // declare a global variable
Function checkscope (){
Scope = "local"; // The global variable is changed.
Document. Write (scope); // The global variable is used.
Myscope = "local"; // implicitly declare the new global variable
Document. Write (myscope); // use the new global variable
}
Checkscope (); // output "locallocal"
Document. Write (scope); // output "local"
Document. Write (myscope); // output "local"
Function definition can be nested
No block-level scope
Undefined and unassigned variables: an error occurs when you read undeclared variables. When you read declared but unassigned variables, the default value undefined is obtained.
Basic type and reference type: Values, Boolean values, null and undefined values belong to the basic type, objects, arrays, and functions belong to the reference type.
Collection of useless storage units: it is automatic and invisible. For example:
VaR S = "hello"; // allocate memory space for a string
VaR u = S. touppercase (); // create a new string
S = u; // overwrite the reference to the original string
As a property variable: the variable is basically the same as the object property.
Global Object: When the javascript interpreter starts running, a global object is created first. The attribute of this object is Program .
Local variable: Call object. When executing a function, the function parameters and local variables are stored as the properties of the called object.
Javascript execution environment:
Deep understanding of variable scope: Scope chain and variable Parsing