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….

Advertisements

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s