有人会解释未定义值和未定义类型之间的区别,以及 null 值和 Null 类型之间的区别吗?
补充:为什么 boolean、string 和 number 有值、类型和对象,而 null 和 undefined 只有值和类型(没有对象)?如果“一切都是对象”,那么人们会假设我们拥有所有可用值的对象,是吗?我的 Infinity 和 NaN 对象在哪里?
最佳答案
null
和 undefined
是值。巧合的是(或者只是一个明智的选择),它们的类型分别是null
undefined
,定义为null
value/type , 未定义
value/type 在规范中。这也可以通过使用 typeof
运算符来显示:
typeof undefined; // "undefined"
typeof null ; // "null" (in ES6) and "object" in <=ES5 (bug)
值与类型相关联,类型表示值的“种类”。
关于javascript - JS : Distinctions between undefined value and Undefined type, 以及空值和空类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11721789/