In Javascript i have read that we can define our own value for undefined. Initially undefined == null is true.
- After we change the value of
undefinedwillundefined == nullstill betrue? - By assigning our own value to
undefineddoes it mean that we can assign real numbers to it? - Why are there two absence of value thingies like
nullandundefined? Couldn’t we just do with one? Is there any difference between them?
undefinedis a variable on the global object which iswindowin browser environments. Its initial value is the primitiveundefined.Being a property on the global object, historically you could have changed its value as,
The meaning of life is now clearly defined. But since EcmaScript-5 is out, this has been disallowed, and even though it is still a property of the global object, it has been made non-writable now.
The primitives
nullandundefinedare not the same thing if no tampering has occurred.Nullis a data type that has the sole valuenull.Undefinedis another data type whose sole value is the primitiveundefined. You can verify whether they represent the same object or not easily.However,
is true, because they are both casted to the boolean value
falsebefore a comparison is made. The rules for converting both these values to boolean are clearly defined in section 9.2 of the spec.