[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment [Back]  [Original]

(||=) - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

(||=)

Baseline

20209

(||=)

const a = { duration: 50, title: "" };

a.duration ||= 10;
console.log(a.duration);
// : 50

a.title ||= "title is empty.";
console.log(a.title);
// : "title is empty."

js
x ||= y

x ||= y x || (x = y) x

x const

js
const x = 1;
x ||= 2;

js
const x = {
  get value() {
    return 1;
  },
  set value(v) {
    console.log("");
  },
};

x.value ||= 2;

js
const x = 1;
x ||= console.log("y ");
// 

"lyrics"

js
document.getElementById("lyrics").textContent ||= "No lyrics.";

: API ||= ( null undefined ) ??=

ECMAScript 2027 LanguageSpecification
# sec-assignment-operators


Web Proxy Viewer  |  New URL  |  Original Page