What is Undefined and Null in JavaScript?

Many people get confused with the difference between undefined and null.  In truth, it’s quite simple to see how it works.

=》Undefined is the default value assigned to any variable.
So, if I created a variable as follows and printed its value, it would be undefined.

var initialVariable;
console.log(initialVariable);

=》Null has to be assigned by the programmer to empty a variable and is not a default value.

var initialVariable = ‘hello’;
initialVariable = null;

Both of these types are considered primitive data types in the JavaScript world.

Programming is Easy….

2 thoughts on “What is Undefined and Null in JavaScript?

Leave a comment