问题描述
null
是
因此不能被覆盖。
null
is a reserved word but not a keyword.
Hence it can not be over-written.
未定义
是可以覆盖的内置全局变量。这就是为什么您看到jQuery在其IIFE中重新定义它的原因。只是为了确保它不会被覆盖。
undefined
is a built in global that can be over-written. This is why you see jQuery re-define it in its IIFE. Just to make sure it was not over-written.
在ES 5中指定何时使用每一个的技术区别是什么。
What it the technical distinction of when to use each as specified in ES 5.
I知道我已经看到浏览器根据浏览器将未创建的localStorage属性设置为null或未定义。
I know that I have seen browsers set an un-created localStorage property to either null or undefined depending upon the browser.
localStorage.not_defined === null // sometimes
localStorage.not_defined === undefined // sometimes
ES 5如何
ES5没有提供澄清:
ES5 provides not clarification:
8.2 Null类型Null类型只有一个值,称为null。
8.2 The Null Type The Null type has exactly one value, called null.
推荐答案
常识如下: undefined
是变量
null
是变量或属性的状态,其中
null
however is a state of a variable or property which indicates that it has no value assigned.
某些方法,例如 getElement ...
显式返回 null
表示结果集为空。如果您的函数没有return语句,则隐式返回 undefined
。
Some methods like getElement...
explicitely return null
to indicate that the resultset is empty. If your function has no return statement, implicitely undefined
is returned instead.
通常,始终分配空
,永不未定义
。
In general, always assign null
and never undefined
.
这篇关于ES5 |何时使用null以及何时使用undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!