写在前面:最近做一些面试题时,发现有很多知识点理解的还是不够充分。。这里集中记录一下,就不再做归类了,都属于 js 基础
题 1.
知识点 :作用域、变量提升等
问题 :试解释以下示例中每一个输出及输出原因
alert(a); // Uncaught ReferenceError: a is not defined
alert(window.a); // undefined
alert(a in window); // Uncaught ReferenceError: a is not defined
alert('a' in window); // false
if(!a) {a = 1;}
alert(a) // Uncaught ReferenceError: a is not defined
if(!window.b) {b = 1;}
alert(b) // 1
if(! "c" in window) {c = 1;}
alert(c) // Uncaught ReferenceError: c is not defined
if(! "d" in window) {var d = 1;}
alert(d) // undefined
if(! "e" in window) {let e = 1;}
alert(e) // Uncaught ReferenceError: e is not defined