null vs undefined in JavaScript
- 1. undefined: Variable declared but not assigned.
- 2. null: Variable intentionally set to no value.
let a;
console.log(a); // undefined
let b = null;
console.log(b); // null
Summary:
undefined = automatic (I haven't given a value yet)
null = intentional (I specifically have no value)
Top comments (0)