/ JavaScript

The Difference Between JavaScript's `undefined` And `null`

The fundamental difference between undefined and null is that, in JavaScript, undefined means a variable has been declared (or not declared), but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Javascript sets unassigned variables with a default value of undefined. Another thing, null is valid in JSON while undefined is not.

let a;

typeof a; // undefined
typeof b; // undefined

let c = null;

typeof c; // object

undefined and null are obviously two different types. undefined is a type itself, while null is an object.

null === undefined // false
Anas Shekhamis

Anas Shekhamis

A software engineer who specializes in architecting and developing web applications. On a daily basis, I use Python, JavaScript, Ruby, and PHP to design and implement API's and build web applications.

Read More
The Difference Between JavaScript's `undefined` And `null`
Share this