Null & undefined
Null is a common concept within programming, found in a LOT of programming languages. It's often stylized as NULL or null, and in some programming languages, they have changed the name to "nil" or "none", but it means the same: Nothing. The concept of null is also called a null pointer or a null reference, because it's basically pointing to something that doesn't (yet) have a value.
let v = null;
If you check the value of this variable, you will see that it's equal to null:
let v = null; alert(v == null);
However, if you declare a variable, without assigning anything to it, it is in fact also equal to null:
let v; alert(v == null);
That makes sense, because as we have already discussed, null can be considered something that points to nothing. But does that mean that these two methods results in a completely identical variable?
let v1 = null; let v2; alert("v1 equality: " + (v1 == null)); // true alert("v2 equality: " + (v2 == null)); // true alert("v1 strict equality: " + (v1 === null)); // true alert("v2 strict equality: " + (v2 === null)); // false
As you can see, as soon as I switch to the strict equality operator, v2 does not equal null, but using the regular equality operator, it is considered the same as null. And in most situations, you won't really need to differentiate between the two.
But when you do, you can compare against the global undefined property, which holds the primitive value of undefined. When we do that, we'll see something that might make things even more confusing: A variable initialized with null as the value, can still be considered "undefined" when we use the regular, non-strict equality operator:
let v1 = null; let v2; alert("v1 equality: " + (v1 == undefined)); // true alert("v2 equality: " + (v2 == undefined)); // true alert("v1 strict equality: " + (v1 === undefined)); // false alert("v2 strict equality: " + (v2 === undefined)); // true