As shown in the title, look at the example below.
(You can use the Chrome browser, then F12/or right-click, inspect the element. Call up the developer tools and enter the console input)
(Usage tips: Shift Enter can break the code midway during console input)
(function(){
var name = name || "小张";
console.info(name);
})();// Xiao Zhang
(function(){
name = name || "小张";
console.info(name);
})(); // xiaoming
(function(){
var name2= name;
var name = name || "小张";
console.info(name, name2);
})(); // Xiao Zhang undefined
The screenshot during execution is as follows:
The explanation is as follows:
In JavaScript.
When executed, it will become this equivalent form: