In JavaScript, undefined represents the value of a variable that wasn’t yet initialized, such as:
var TestVar;
alert(TestVar);
alert(typeof TestVar);
It is an assignment value, which is used with variable to represent no value.
var TestVar = null;
alert(TestVar);
alert(typeof TestVar);
From the preceding examples, it is clear that undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
In JavaScript, undefined represents the value of a variable that wasn’t yet initialized, such as:
var TestVar; alert(TestVar); //shows undefined alert(typeof TestVar); //shows undefinedIt is an assignment value, which is used with variable to represent no value.
var TestVar = null; alert(TestVar); //shows null alert(typeof TestVar); //shows objectFrom the preceding examples, it is clear that undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.