DEV Community

Cover image for Weird JS
Rahul Kumar Jha
Rahul Kumar Jha

Posted on

Weird JS

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
Enter fullscreen mode Exit fullscreen mode

Summary:
undefined = automatic (I haven't given a value yet)
null = intentional (I specifically have no value)

Top comments (0)