Is Null An Object In Javascript?
Solution 1:
Null is the absence of an object. Undefined means it hasn't been assigned yet, and null means it has been assigned to be nothing.
Null is not really a singleton object, because dereferencing it will cause an error; for (var x in null)
will give you an error. Think back to the pointer days; null was the value a pointer had when it was not pointing to an object.
Solution 2:
No, null is one of the few primitive types (others being numbers, strings, booleans, and undefined). Everything else is an object, including functions, arrays and regular expressions. Numbers, strings and booleans are often called "object-like", because they have methods, but they are immutable. Objects on the other hand are mutable.
Solution 3:
null
can't be considered an object because it cannot have properties. It is a keyword representing a primitive, like true
and false
.
> trueinstanceofObjectfalse
> nullinstanceofObjectfalse
Post a Comment for "Is Null An Object In Javascript?"