Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Double negation

Double negation (!!) converts any JavaScript value to a boolean primitive using its truthiness. It is equivalent to Boolean(value).

How it works

The first ! converts a value to a boolean and reverses it; the second ! reverses that boolean again. The result is therefore the ordinary truthiness conversion, equivalent to Boolean(value), producing only true or false.

Syntax

!!value

Returns

A boolean primitive: true or false.

Key points

  • Write !!value when an expression must be normalized to the primitive boolean true or false.
  • Each ! is unary, so double negation consists of two unary operations applied in sequence to one value.
  • The first ! performs the conversion step before producing its inverted result.
  • Applying the second ! cancels the inversion while retaining the boolean conversion.

Common mistakes

  • Because ! has higher precedence than && and ||, each negation is evaluated before those logical operators.
  • The first negation does not preserve the original value: it first applies boolean conversion and then returns the opposite boolean.

Example: Convert values with double negation

const values = ["hello", "", 0, 42, null, {}];
const flags = values.map(value => !!value);
console.log(flags);
// [true, false, false, true, false, true]

Applying ! twice converts each value to its boolean equivalent.

When to use it

Create a boolean flag

Normalize an optional or mixed-type expression before storing or passing a flag.

Booleanize an operand

Convert a value while composing a larger logical expression that expects a boolean operand.

Expose truthiness

Make a value's truthiness explicit in a compact expression.

Interview questions

QWhat does !!value do?

Double negation uses two logical NOT operations: the first converts the operand to a boolean and inverts it, while the second inverts that result. The final value is therefore true or false according to the operand's truthiness.

Follow-up: How can the same conversion be written without !!? Use Boolean(value), which performs the direct boolean conversion.

QWhich values become false with double negation?

Falsy values such as 0, an empty string, null, undefined, and NaN become false; other values become true. Thus !!value reflects JavaScript's boolean-conversion rules rather than preserving the original type.

Follow-up: What about the string "0"? It is non-empty, so it converts to true.

QWhat is the syntax and precedence behavior of double negation?

The expression is written as !!value. Since logical NOT has high precedence, a chain such as !!value && other is evaluated as (!!value) && other.

Follow-up: How can precedence be made explicit? Add parentheses, for example (!!value) && other.

  • Logical NOT (!)
  • Boolean conversion
  • Logical AND (&&)
  • Logical OR (||)

Source: Logical operators - The Modern JavaScript Tutorial. Checked 2026-10-15.