From 5c0ea294ce0f16f4a07c3d3b794b10145ba920a5 Mon Sep 17 00:00:00 2001 From: Vaibhav Soni <49754221+vsoni101@users.noreply.github.com> Date: Thu, 3 Dec 2020 09:08:02 +0000 Subject: [PATCH 1/3] Update article.md In the section "String concatenation with binary +", the example of 2 + 2 + "1" was given, but there was no example for when the first operand is a string. --- 1-js/02-first-steps/08-operators/article.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index 0aaaf512..bb5f3f56 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -106,6 +106,11 @@ alert(2 + 2 + '1' ); // "41" and not "221" Here, operators work one after another. The first `+` sums two numbers, so it returns `4`, then the next `+` adds the string `1` to it, so it's like `4 + '1' = 41`. +```js run +alert('1' + 2 + 2); // "122" and not "14" +``` +Here, the first operand is a string, the compiller treats the other two operands as string too. The `2` gets concatinated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"` + The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers. Here's the demo for subtraction and division: From 634e0668419351fdf06e70ead2c14a26a1a02ff9 Mon Sep 17 00:00:00 2001 From: Vaibhav Soni <49754221+vsoni101@users.noreply.github.com> Date: Thu, 3 Dec 2020 15:21:13 +0000 Subject: [PATCH 2/3] Update 1-js/02-first-steps/08-operators/article.md Co-authored-by: Vse Mozhe Buty --- 1-js/02-first-steps/08-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index bb5f3f56..1beacd73 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -109,7 +109,7 @@ Here, operators work one after another. The first `+` sums two numbers, so it re ```js run alert('1' + 2 + 2); // "122" and not "14" ``` -Here, the first operand is a string, the compiller treats the other two operands as string too. The `2` gets concatinated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"` +Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = '12'` and `'12' + 2 = '122'`. The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers. From 3d86152fdd93fafdbd1c4863460651effdcec9dc Mon Sep 17 00:00:00 2001 From: Vaibhav Soni <49754221+vsoni101@users.noreply.github.com> Date: Thu, 3 Dec 2020 18:51:18 +0000 Subject: [PATCH 3/3] Update article.md Fix some quotes for consistency with above paragraphs --- 1-js/02-first-steps/08-operators/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index 1beacd73..45b1f342 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -109,7 +109,7 @@ Here, operators work one after another. The first `+` sums two numbers, so it re ```js run alert('1' + 2 + 2); // "122" and not "14" ``` -Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = '12'` and `'12' + 2 = '122'`. +Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`. The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers.