简体   繁体   中英

How does a JavaScript interpreter handle null?

I've been wondering about the use of the keyword null in the JS language. In cases like C/C++, NULL is stood to mean something like a null pointer, ie a pointer to 0 (though there are macro definitions, etc, which can change this), but how is JS specified to handle the keyword? Is there some specification that says how it should be processed?

null is a literal in javascript which indicates an empty value or an empty object. This should not be confused however, with undefined which is the value of an uninitialized variable or object. Moreover, care has to be taken always when using the equality operator ( == ) or the identity operator ( === ) on null and undefined values, as the comparison gives totally different result depending on what operator is used:

From the Mozilla Developer Docs :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM