In this article, we’ll see what is the difference between undefined and null in javascript.
undefined
: means a variable has been declared but has not yet been assigned a value.
Below an example:
var UndefinedVar; console.log(UndefinedVar); //shows undefined console.log(typeof UndefinedVar); //shows undefined
null
: means an empty or non-existent value. It can be assigned to a variable as a representation of no value.
Below an example:
var NullVar = null; console.log(NullVar); //shows null console.log(typeof NullVar); //shows object
In above examples, we’ve seen that undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.
null === undefined // false null == undefined // true null === null // true
Here are the quick facts:
null
is an assigned value. It means nothing.undefined
means a variable has been declared but not defined yetnull
is an object.undefined
is of type undefined.null
!==undefined
butnull
==undefined
.
That’s it!. Please share your thoughts or suggestions in the comments below.
This is my first time pay a quick visit at here
and i am genuinely pleassant to read everthing at alone place.
Thanks Starkey..