From 92cb04434ff7ec57b7e43bc46b4d6300c9dccb30 Mon Sep 17 00:00:00 2001 From: Tansica Sun <42325298+tjs13@users.noreply.github.com> Date: Tue, 13 Nov 2018 20:13:34 -0800 Subject: [PATCH] Clarified + in addition and concatenation (#21433) Distinguished `+` function (arithmetic versus concatenation) when dealing with different data types (number versus string). --- .../english/javascript/arithmetic-operation/index.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/guide/english/javascript/arithmetic-operation/index.md b/guide/english/javascript/arithmetic-operation/index.md index 0e8f22b134..5ed60719fe 100644 --- a/guide/english/javascript/arithmetic-operation/index.md +++ b/guide/english/javascript/arithmetic-operation/index.md @@ -9,9 +9,21 @@ JavaScript provides five arithmetic operators: `+`, `-`, `*`, `/` and `%`. The o `a + b` +**Caution** +
+The `+` serves as an arithmetic operator and for concatenating strings. Take extra caution when dealing with numbers versus string data types. + +If `a` and `b` data types are both numbers, their value will add. +
+If `a` is a number and `"b"` is a string, their value will concatenate into a string. +
+If `"a"` and `"b"` are both strings, their value will concatenate into a string. + **Usage** 2 + 3 // returns 5 + 5 + "3" // returns "53" + "10" + "40" // returns "1040" true + 2 // interprets true as 1 and returns 3 false + 5 // interprets false as 0 and returns 5 true + "bar" // concatenates the boolean value and returns "truebar"