Operators

Nullish assignment (??=)

Try the free JavaScript compiler

Writes the right value only when the current target is null or undefined. It preserves other falsy values. The target is evaluated once and the right side is conditional.

Formal Syntax & Structure

javascript syntaxjavascript
target ??= fallback

Parameters & Attributes

NameTypeDescription
targetassignment targetCurrent value is tested before a possible write.
fallbackexpressionEvaluated only when the relevant condition holds.

Return Value

operand value

Old value if skipped, otherwise the written value.

Working Example

Example Snippetjavascript
let n = null;console.log(n ??= 8);
JavaScript Reference