As the title shows, look at the example below.
(You can use the Chrome browser and then f12/or right button to review the elements.) Pull up the developer tool and enter the console console input.
(Tips: When the console is entered, Shift+enter can be wrapped in code).
Copy Code code as follows:
var name = "Xiaoming";
(function () {
var name = name | | "Xiao Zhang";
Console.info (name);
}) ()//small Zhang
(function () {
Name = Name | | "Xiao Zhang";
Console.info (name);
})(); Xiaoming
(function () {
var name2= name;
var name = name | | "Xiao Zhang";
Console.info (name, name2);
})(); Xiao Zhang undefined
The screenshot of the execution is as follows:
Explained as follows:
In JavaScript.
Copy Code code as follows:
function xxx () {
A bunch of code ...
// ...
var name2 = name;
var name = name | | "Xiao Zhang";
A bunch of code
}
Execution becomes this equivalence form:
Copy Code code as follows:
function xxx () {
var name2 = undefined;
var name = undefined;
Other Var will also be advanced to the starting point
A bunch of code ...
// ...
name2 = name;
Name = Name | | "Xiao Zhang";
A bunch of code
}