Inconsistency with null

Sakthipriyan Vairamani sakthiprofessional at gmail.com
Sun May 11 20:43:38 PDT 2014


console.log(typeof null);
​# object​

​console.log(Object.prototype.toString.call(null));
#​
​ [object Null]​


​This means that null​
​ is expected to be an object. But,

​
​console.log(Object.keys(null));​

​# TypeError: Object.keys called on non-object​


 ​The error message says that null​
​ is a non-object. It contradicts the result of typeof and toString.

*Question 1:* Why does it behave so? Is this something which has to be
fixed?

Also, null is not a keyword <http://es5.github.io/#x7.6.1.1>, but when I do

​
​var null = 1;
# SyntaxError: Unexpected token null​


​It fails with the Syntax Error, since it is a Reserved
Word<http://es5.github.io/#x7.6.1>
.

*Question 2:* What is the purpose of keeping null and boolean literals as
"Reserved words" and not just keywords?

Note: I tried these samples in node v0.11.13-pre

- Thanks and Regards,

Sakthipriyan Vairamani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140512/08e758f5/attachment.html>


More information about the es-discuss mailing list