Skip to main content
The logical NOT (!) is a unary operator that evaluates its operand, coerces the resulting value to a boolean primitive, and returns the logical complement of that boolean. If the operand is truthy, it returns false; if the operand is falsy, it returns true.

Mechanics and Type Coercion

When the JavaScript engine evaluates the ! operator, it executes the following sequence:
  1. Evaluates the provided expression.
  2. Applies the internal ECMAScript ToBoolean abstract operation to the evaluated result.
  3. Inverts the resulting boolean value.
Because JavaScript employs implicit type coercion, the ! operator does not require a boolean operand. The language’s truthiness and falsiness rules allow the operator to accept any data type and force coercion to a boolean primitive.

Falsy Evaluation

Applying ! to any falsy value strictly yields true. JavaScript defines exactly eight falsy values. The operator evaluates all of the following to true:

Truthy Evaluation

Applying ! to any value not present in the falsy list yields false. This includes all objects, arrays, and functions, regardless of whether they are empty.

Operator Precedence

The ! operator has a very high precedence, sitting below grouping () and member access, but above all arithmetic, relational, and equality operators. It associates right-to-left. Because of this high precedence, it binds tightly to its immediate operand.

Double NOT (!!)

Stacking two logical NOT operators (!!) is syntactically valid. The first ! coerces the operand to a boolean and inverts it. The second ! inverts it back. Mechanically, this exposes the exact result of the internal ToBoolean operation without the final inversion.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More