The JavaScript keyword null is a special value that indicates no value.null is usually considered a special value of object typea value that represents no object.
When a variable holds the value null, you know that it does not contain a valid object, array, number, string, or boolean value
null代表着没有值
undefined is returned when you use either a variable that has been declared but never had a value assigned to it or an object property that does not exist.
undefined代表着两种情况:申明了变量却没有赋值;对象的属性不存在。
Since both null and the undefined value indicate an absence of value, this equality is often what we want. However, if you truly must distinguish between anull value and an undefined value, use the === identity operator or thetypeof operator
对于一个不存在的值来说,undefined和null是一样的效果。如果你一定要区分是null和undefined的话,你可以用操作符=== 或者是typeof。null的类型是object而undefined的类型确是undefined
本文探讨了JavaScript中null与undefined的含义及区别。null表示一个空值或没有值的对象引用,而undefined则通常用于表示未初始化的变量或不存在的对象属性。文章还介绍了如何使用===操作符或typeof来区分这两个值。
864

被折叠的 条评论
为什么被折叠?



