虽然字面上使用关键字 _undefined_,`Boolean(undefined)` 可以工作,尝试使用未定义的 _variable_ **不** 工作,这就是检查 null 或 undefined 的全部意义所在。这:`if (Boolean(undeclareVarName)) { console.log('yes'); } else { console.log('no'); }` 抛出一个 ReferenceError 说“ReferenceError: unde...
第二种情况test方法里的age因为没有声明(undeclared),被JS引擎当做全局变量使用,所以在test方法外也能被获取到,而yourAge在test方法里被正确声明以及赋值,它的作用域仅限于在test方法内被使用,所以想从方法外调用时会报错,因为无法在test()方法外找到yourAge变量,和第一种的undeclare相似。 undefined 和 null null...