Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

加算代入演算子 (+=)

BaselineWidely available

加算代入 (+=) 演算子は、 2 つのオペランドの加算(数値の加算または文字列の結合のどちらか)を実行し、左オペランドへ結果を代入します。

試してみましょう

let a = 2;let b = "hello";console.log((a += 3)); // 加算// 予想される出力: 5console.log((b += " world")); // 結合// 予想される出力: "hello world"

構文

js
x += y

解説

x += yx = x + y と同等ですが、式x は一度しか評価されません。

数値を使用した加算代入

js
let bar = 5;bar += 2; // 7

それ以外の文字列でも長整数でもない値は、数値に変換されます。

js
let baz = true;baz += 1; // 2baz += false; // 2

長整数を使用した加算代入

js
let x = 1n;x += 2n; // 3nx += 1; // TypeError: Cannot mix BigInt and other types, use explicit conversions

文字列を使用した加算代入

js
let foo = "foo";foo += false; // "foofalse"foo += "bar"; // "foofalsebar"let bar = 5;bar += "foo"; // "5foo"

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-assignment-operators

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp