From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../operators/addition_assignment/index.html | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 files/ja/web/javascript/reference/operators/addition_assignment/index.html (limited to 'files/ja/web/javascript/reference/operators/addition_assignment/index.html') diff --git a/files/ja/web/javascript/reference/operators/addition_assignment/index.html b/files/ja/web/javascript/reference/operators/addition_assignment/index.html new file mode 100644 index 0000000000..d2e2a59492 --- /dev/null +++ b/files/ja/web/javascript/reference/operators/addition_assignment/index.html @@ -0,0 +1,78 @@ +--- +title: 加算代入 (+=) +slug: Web/JavaScript/Reference/Operators/Addition_assignment +tags: + - Assignment operator + - JavaScript + - Language feature + - Operator + - Reference +translation_of: Web/JavaScript/Reference/Operators/Addition_assignment +--- +
{{jsSidebar("Operators")}}
+ +

加算代入演算子 (+=) は、右辺のオペランドの値を変数に加算し、結果を変数に代入します。 2つのオペランドの型は、加算代入演算子の動作を決定します。加算もしくは連結が可能です。

+ +
{{EmbedInteractiveExample("pages/js/expressions-addition-assignment.html")}}
+ +
+ + + +

構文

+ +
Operator: x += y
+Meaning:  x  = x + y
+ +

+ +

加算代入の使用

+ +
// 以下の変数を想定
+//  foo = 'foo'
+//  bar = 5
+//  baz = true
+
+// 数値 + 数値 -> 加算
+bar += 2 // 7
+
+// ブール値 + 数値 -> 加算
+baz += 1 // 2
+
+// ブール値 + ブール値 -> 加算
+baz += false // 1
+
+// 数値 + 文字列 -> 連結
+bar += 'foo' // "5foo"
+
+// 文字列 + ブール値 -> 連結
+foo += false // "foofalse"
+
+// 文字列 + 文字列 -> 連結
+foo += 'bar' // "foobar"
+ +

仕様

+ + + + + + + + + + +
仕様
{{SpecName('ESDraft', '#sec-assignment-operators', 'Assignment operators')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("javascript.operators.addition_assignment")}}

+ +

関連項目

+ + -- cgit v1.2.3-54-g00ecf