Undefined Vs Null in JavaScript
Undefined means a variable has been declared but not assign any value. While null is an assignment value. It can be assigned to a variable that represent no value.
For Example:
var x;
alert(typeof(x));
var y = null;
alert(typeof(y));
output of above example:
undefined
object
From above example, it is very clear that undefined and null are two distinct types:
By default Unassigned variables is undefined which is automatically initialized by JavaScript. JavaScript never sets a value to null but this can be done by programmatically.
0 Comment(s)