Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

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

1 Answer

0 votes
by (19.7k 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

Browse Categories

...