Skip to content

logical NOT (!)

In JavaScript, the logical NOT operator (!) converts its single operand to a Boolean and returns the opposite value. It returns false for a truthy operand and true for a falsy one, so its result is always true or false.

The result is a boolean even when the operand isn’t. The falsy values that make ! return true are false, 0, -0, 0n, "", NaN, null, and undefined. Apart from the legacy browser object document.all, every other value is truthy, including "0", "false", empty arrays, and empty objects.

Applying the operator twice, as in !!value, is the double NOT idiom. The first ! converts and flips, and the second flips back, which leaves the operand’s Boolean equivalent. It returns the same value as calling Boolean() as a function.

JavaScript Logical NOT Syntax

The operator goes before its operand, once to negate or twice to convert:

Language: JavaScript Syntax
!<operand>
!!<operand>

As a unary operator, ! binds more tightly than the comparison and logical operators. That means !isAdmin && isOwner reads as (!isAdmin) && isOwner, with the logical AND operator (&&) applied last.

JavaScript Logical NOT Examples

A sign-up form keeps its submit button disabled while the name field is empty. Because "" is falsy, ! turns the empty field into true:

Language: JavaScript
> const userName = "";
undefined

> !userName
true

> !"Ada"
false

While !userName is true, the form keeps the button disabled. Once the field holds any character, the string is truthy and ! returns false.

A shopping cart object stores an item count and a coupon code, but the code that reads it needs strict Boolean flags. The double NOT idiom converts each value without changing its truthiness:

Language: JavaScript
> const cart = { items: 0, coupon: "SAVE10" };
undefined

> ({ hasItems: !!cart.items, hasCoupon: !!cart.coupon })
{ hasItems: false, hasCoupon: true }

> !!"false"
true

The count 0 becomes false, and the coupon string becomes true. The last prompt shows that !! checks only truthiness. The non-empty string "false" converts to true.

JavaScript Logical NOT Gotchas

  • Because ! binds before comparisons, !role === "admin" compares a Boolean to a string and is always false. Parentheses fix it, as in !(role === "admin"), or the !== operator does.
  • An empty array or object is truthy, so ![] returns false. Testing an array for emptiness takes .length, as in !items.length.
  • A check such as !price treats a valid 0 or "" the same as null and undefined, so it rejects real data along with missing values.

JavaScript Logical NOT Use Cases

  • Toggling a Boolean flag, as in isOpen = !isOpen
  • Negating a condition in an if statement or a while loop
  • Checking that a value is missing or empty before using it
  • Converting a value to a strict Boolean with !!value
  • Inverting a predicate, as in items.filter((item) => !item.archived)

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 12, 2026