Logical Assignment Operators

Med

Logical assignment operators: ??= (nullish), ||= (OR), &&= (AND). Assign conditionally based on current value.

Interactive Visualization

Destructuring

Old Way
const user = { name: "Alice", age: 25 };
const name = user.name;
const age = user.age;
Modern Way
Click transform to see

Key Points

  • x ??= y (nullish)
  • x ||= y (falsy)
  • x &&= y (truthy)
  • Conditional assignment

Code Examples

Logical Assignment

let count = null;
count ??= 0; // sets to 0

let name = "";
name ||= "Anonymous"; // sets to "Anonymous"

let value = "hello";
value &&= value.toUpperCase(); // "HELLO"

Assign based on current value state