1, undeclared variables are assigned, this variable is the global variable of the Window object all
Console.log (a); A is not defined
a=10
Console.log (a); 10 equivalent to Console.log (WINDOW.A)
function Test () {
var a = b = 123;
}
Test ();
Console.log (b) //123
Console.log (a) //a is not defined
2. All declared variables are properties of the Window object.
var aaa=111;
var bbb=222;
var ccc=333;
Equivalent to window{aaa:111,bbb:222,ccc:333}
3, pre-compilation occurs in the first moment of function execution, there are the following four steps:
(1), create AO (Activation object/Execution period context) objects;
(2), find formal parameter and variable declaration, the variable and formal parameter name is AO object attribute name, value is undefined;
(3), the integration of the actual parameters and formal parameters;
(4), in the function body found function declaration, the value assigned to the function body;
function fn (a) {
Console.log (a); //? A () {}
Console.log (a); 123
function A () {}
Console.log (a); 123
var B = function () {}
Console.log (b); //? () { }
}
fn (1);
JS pre-compilation, global variables, local variables related knowledge