Skip to content Skip to sidebar Skip to footer

Is Null An Object In Javascript?

Possible Duplicate: Null object in javascript Hi, I've read this thread about null in JavaScript, but I'm very confused about the identity of null now. As it is known that type

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?"