2015-04-23 77 views
0

我一直想知道在JS语言中使用关键字null。在像C/C++这样的情况下,NULL被认为是类似于空指针的东西,即指向0的指针(虽然有宏定义等可以改变这种情况),但JS如何指定处理关键字?是否有一些说明应该如何处理?JavaScript解释器如何处理null?

+0

看这个帖子,可能是有用的 http://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank -variables-in –

+0

这对你将如何使用它有什么影响吗?可能与http://stackoverflow.com/questions/801032/why-is-null-an-object-and-whats-the-difference-between-null-and-undefined – Krease

+0

@DiogoPaim这是一个很好的参考,但它并不完全回答JS解释器如何处理关键字。 –

回答

0

null是javascript中的文字,表示空值或空对象。但是,这不应与undefined混淆,这是未初始化的变量或对象的值。此外,保健已使用等于运算符(==)或身份运营商(===)对null和undefined值时要始终把,作为比较给出完全不同的结果,这取决于使用何种操作:

Mozilla Developer Docs

typeof null  // object (bug in ECMAScript, should be null) 
typeof undefined // undefined 
null === undefined // false 
null == undefined // true