Operators
Nullish assignment (??=)
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 ??= fallbackParameters & Attributes
| Name | Type | Description |
|---|---|---|
| target | assignment target | Current value is tested before a possible write. |
| fallback | expression | Evaluated 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);