Difference between null and undefined in JavaScript


Below explain the difference between null and undefined in JavaScript

undefined in JavaScript

The undefined means a variable has been declared but has no value.

var nameTest;
console.log(nameTest); //undefined
console.log(typeof nameTest); //undefined

null in JavaScript

null is an assignment value,Variable declared and is an empty value

var nameTest=null;
console.log(nameTest); //null
console.log(typeof nameTest); //object


Related

String Concatenation in JavaScript
Tag Template literals (Strings) in JavaScript
Destructuring assignment in JavaScript
localStorage, sessionStorage and cookies in JavaScript?
How to play multiple video in loop using HTML5 and JavaScript