lzcdev / Daily-Front-End-Questions

每日前端面试题、技巧等知识点,记录自己的成长过程
MIT License
1 stars 0 forks source link

输出什么?(变量提升) #35

Open lzcdev opened 5 years ago

lzcdev commented 5 years ago
var name = 'Tom';
(function () {
  if (typeof name == 'undefined') {
    var name = 'Jack'
    console.log(name);    
  } else {
    console.log(name);
  }
})();
lzcdev commented 5 years ago

Jack 关键在于var