Skip to content

Latest commit

 

History

History
23 lines (15 loc) · 486 Bytes

File metadata and controls

23 lines (15 loc) · 486 Bytes

Difference null, undefined, undeclared

A variable is said to be undeclared when you are trying to use it before you even declare it - it doesn't exist.

console.log(a); //ReferenceError: a is not defined

null is a value given to a variable to indicate that it is empty.

var a = null;
console.log(a); // null

A variable is undefined when it is used but does not have a value.

var a;
console.log(a); // undefined