Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Logical NOT (!)

BaselineWidely available

Thelogical NOT (!) (logical complement, negation) operator takes truth tofalsity and vice versa. It is typically used with boolean (logical)values. When used with non-Boolean values, it returnsfalse if its singleoperand can be converted totrue; otherwise, returnstrue.

Try it

const a = 3;const b = -2;console.log(!(a > 0 || b > 0));// Expected output: false

Syntax

js
!x

Description

Returnsfalse if its single operand can be converted totrue;otherwise, returnstrue.

If a value can be converted totrue, the value is so-calledtruthy. If a value can be converted tofalse, the value isso-calledfalsy.

Examples of expressions that can be converted to false are:

  • null;
  • NaN;
  • 0;
  • empty string ("" or'' or``);
  • undefined.

Even though the! operator can be used with operands that are not Boolean values, it can still be considered a boolean operator since its return value can always be converted to aboolean primitive. To explicitly convert its return value (or any expression in general) to the corresponding boolean value, use a double NOT operator (!!) or theBoolean constructor.

Examples

Using NOT

The following code shows examples of the! (logical NOT) operator.

js
!true; // !t returns false!false; // !f returns true!""; // !f returns true!"Cat"; // !t returns false

Double NOT (!!)

It is possible to use a couple of NOT operators in series to explicitly force theconversion of any value to the correspondingboolean primitive.The conversion is based on the "truthiness" or "falsiness" of the value (seetruthy andfalsy).

The same conversion can be done through theBoolean() function.

js
!!true; // !!truthy returns true!!{}; // !!truthy returns true: any object is truthy…!!new Boolean(false); // … even Boolean objects with a false .valueOf()!!!false; // !!falsy returns false!!""; // !!falsy returns false!!Boolean(false); // !!falsy returns false

Converting between NOTs

The following operation involvingbooleans:

js
!!bCondition

is always equal to:

js
bCondition

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-logical-not-operator

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp