Header Ads

Difference between 0,null, undefined

 Key Differences:

null is an object, whereas undefined is a type of its own.

null is typically used to indicate a deliberate non-value, while undefined signifies an uninitialized variable.

0 is a number and is used in numerical contexts.


JavaScript - 0 null undefined


 

let a;

console.log(a); // undefined (a is declared but not assigned)

 
a = null;

console.log(a); // null (a is intentionally set to have no value)

a = 0;

console.log(a); // 0 (a is assigned a numerical value o f zero)

Powered by Blogger.