What is the difference between null and undefined in JavaScript?

JavascriptWeb DevelopmentFront End Technology

In JavaScript, undefined is a type, whereas null an object.

undefined

It means a variable declared, but no value has been assigned a value.

For example,

var demo;
alert(demo); //shows undefined
alert(typeof demo); //shows undefined

null

Whereas, null in JavaScript is an assignment value. You can assign it to a variable.

For example,

var demo = null;
alert(demo); //shows null
alert(typeof demo); //shows object
raja
Published on 09-Jan-2018 13:14:09
Advertisements