代入 (=)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
単純代入演算子 (=
) は、変数に値を代入するために使用されます。割り当て操作は、割り当てられた値として評価されます。代入演算子を使用して、単一の値を複数の変数に割り当てることができます。
試してみましょう
let x = 2;
const y = 3;
console.log(x);
// Expected output: 2
console.log((x = y + 1)); // 3 + 1
// Expected output: 4
console.log((x = x * y)); // 4 * 3
// Expected output: 12
構文
js
x = y;
例
代入と連鎖
js
// 以下の変数を想定
// x = 5
// y = 10
// z = 25
x = y; // x は 10
x = y = z; // x, y そして z はすべて 25
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-assignment-operators |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Assignment ( x = y ) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.