Skip to content
blog
2 min read

Not Operator

The ! operator inverts truthy and falsy values. Learn how to use NOT and double negation to write cleaner conditional logic in JavaScript.

The ! (NOT) operator flips a boolean value. true becomes false, false becomes true.

Basic Usage

!true; // false
!false; // true

It’s most useful in conditions:

const isLoggedIn = false;
if (!isLoggedIn) {
console.log("Please log in"); // this runs
}

Reading it: “if NOT logged in”.

Truthy and Falsy

JavaScript values are either truthy or falsy. ! converts them to their boolean opposite:

!0; // true — 0 is falsy
!""; // true — empty string is falsy
!null; // true
!undefined; // true
!NaN; // true
!1; // false — non-zero numbers are truthy
!"hello"; // false — non-empty strings are truthy
![]; // false — arrays are truthy (even empty ones)
!{}; // false — objects are truthy (even empty ones)

Double Negation !!

!! converts any value to its actual boolean equivalent:

!!0; // false
!!1; // true
!!""; // false
!!"hello"; // true
!!null; // false
!![]; // true

This is useful when you need a real true or false instead of a truthy/falsy value — for example, when storing something in state or comparing with ===.

In Conditions

You don’t need !! in an if statement — JavaScript already coerces the value:

// These are equivalent
if (!!value) { ... }
if (value) { ... }

Use !! when you explicitly need a boolean type, not just truthy/falsy behavior.