Example 1 — *= and friends
Arithmetic updates.
JavaScript
let x = 4; x *= 2; console.log(x); How It Works
- Multiply and store.
Assignment operators store a value in a variable. Shortcuts like += update in place. Modern logical assignments (&&=, ||=, ??=) assign only when a condition holds.
let n = 2;
n += 3;
console.log(n);
let city = null;
city ??= "London";
console.log(city); Arithmetic updates.
let x = 4; x *= 2; console.log(x); Assign if current value is falsy.
let t = ""; t ||= "hi"; console.log(t); Assign if current value is truthy.
let t = "a"; t &&= "b"; console.log(t); CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful