undefined vs null in JavaScript
In last article I explained how to use variables in JavaScript but I also mentioned undefined, here I will try my best to explain to you what is undefined, what is the difference with null, why both are existing and I will give you some examples.
und...
gillesferrand.com2 min read
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.