0 votes
1 view
in Java by (9.2k points)

Can anyone tell me what’s the difference between null and undefined in JavaScript?

1 Answer

0 votes
by (19k points)
  1. Undefined is a variable which is declared but not been yet assigned a value like below:

var testVar;

alert(testVar); //shows undefined

alert(typeof testVar); //shows undefined

  1. Null is variable with an assignment value to represent it contains no value:

var testVar = null;

alert(testVar); //shows null

alert(typeof testVar); //shows object

Interested in Java? Check out this Java Certification by Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...