You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var name = 'Tom';
(function() {
if (typeof name == 'undefined') {
var name = 'Jack';
console.log('Goodbye ' + name);
} else {
console.log('Hello ' + name);
}
})();
解答:
Goodbye Jack
var 声明的变量没有块作用域,变量会提升到最近的 function 作用域的上层,但此时只是声明了变量,并没有赋值,到实际运行了赋值语句之后才有值,在之前值为 undefined
The text was updated successfully, but these errors were encountered:
解答:
Goodbye Jack
var 声明的变量没有块作用域,变量会提升到最近的 function 作用域的上层,但此时只是声明了变量,并没有赋值,到实际运行了赋值语句之后才有值,在之前值为 undefined
The text was updated successfully, but these errors were encountered: