Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Logical NOT operator (!)

The ! operator converts its operand to a Boolean and reverses it. It returns true for falsy values and false for truthy values. Double negation, !!, produces a Boolean without reversing its meaning.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

!expression
!(expression)
!!expression

!expression is unary logical negation. It first evaluates expression, then applies the ToBoolean conversion and reverses the result. If evaluating the operand completes normally, the result is always true or false, not the original operand value.

The falsy values are false, undefined, null, 0, -0, NaN, 0n, and the empty string "". Other values are truthy, including "false", "0", empty arrays, and ordinary objects. A legacy web-compatibility exception covers objects with the internal slot [[IsHTMLDDA]], which are also falsy.

Writing !!expression applies two ! operators; it is not a separate operator. It produces the same Boolean value as Boolean(expression). It does not validate data or check whether a collection contains elements: !![] is true.

Use parentheses to negate an entire comparison: !(a === b). Writing !a === b compares the already-negated a with b. Do not confuse logical negation ! with bitwise NOT ~ or the inequality operators != and !==.

Examples

const values = [false, 0, "", "false", [], null];
for (const value of values) {
  console.log(`${!value} ${!!value}`);
}

Result

true false
true false
true false
false true
false true
true false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources