Undefined is a type whose sole value is undefined (notice the lower case u). The undefined (lower case u again!) value is a primitive value (recall that Undefined is one of the primitive types) that is used when a variable hasn’t been assigned a value. Here’s an example:
To sum up, whenever you declare a variable and don’t initialize it, it will end up with an undefined value. Notice that the existence of undefined value lets you distinguish between declared variables that have been initialized or not. Take a look at the following example:
As you can see, you can initialize a variable to null. When this happens, the value no longer returns undefined, but null. null is also a primitive value and it was introduced in the language to represent the intentional absence of any value (notice that a variable initialized or set to null has been initialized and that means it’s not undefined). Since we’re talking about null, I’m going to take this opportunity to mention that null is the only value of the primitive Null type (yes, we have those nasty case differences between type and value again ).
And I guess that it’s all for now. Stay tuned for more!