undefined means a variable has been declared but has not yet been assigned a value.
var TestVar;
alert(TestVar);
alert(typeof TestVar);
null is an assignment value. It can be assigned to a variable as a representation of 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.
undefined means a variable has been declared but has not yet been assigned a value.
var TestVar; alert(TestVar); //shows undefined alert(typeof TestVar); //shows undefinednull is an assignment value. It can be assigned to a variable as a representation of 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.