fe-weekly-questions icon indicating copy to clipboard operation
fe-weekly-questions copied to clipboard

undefined 与 undeclared 的区别?

Open LuckyWinty opened this issue 4 years ago • 0 comments

已在作用域中声明但还没有赋值的变量,是 undefined 的。相反,还没有在作用域中声明 过的变量,是 undeclared 的。对于 undeclared 变量的引用,浏览器会报引用错误,如 ReferenceError: b is not defined 。但是我们可以使用 typeof 的安全防范机制来避免 报错,因为对于 undeclared(或者 not defined )变量,typeof 会返回 "undefined"。

LuckyWinty avatar Oct 18 '20 12:10 LuckyWinty