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 typeof(null)
evaluates to object
because of the language design error, and ECMA states that null is The Null Type
.
8.2 The Null Type
The Null type has exactly one value, called null.
So why people keep saying that null
is an object?
Someone said null is a singleton object. Is that how everybody sees the null as in JavaScript too?
null is not an object, it is a primitive value. For example, you cannot add properties to it. Sometimes people wrongly assume that it is an object, because typeof null returns "object" . But that is actually a bug (that might even be fixed in ECMAScript 6).
The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy for boolean operations.
'Null' is a keyword in JavaScript that signifies 'no value' or nonexistence of any value. If you wish to shred a variable off its assigned value, you can simply assign 'null' to it. Besides this, like any other object, it is never implicitly assigned to a variable by JavaScript.
There are only seven values that are falsy in JavaScript, and empty objects are not one of them. An empty object is an object that has no properties of its own. You can use the Object. keys() function to check if an object is empty as shown below.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With