
( ++x), returns the value of its operand after adding one Returns the integer remainder of dividing the two *, /), JavaScript provides the arithmetic operators listed inīinary operator. In addition to the standard arithmetic operations ( +, -, Tmp = x * y x *= y z += tmp (except without the tmp).įor more complex assignments, the destructuringĪssignment syntax is a JavaScript expression that makes it possible to extractĭata from arrays or objects using a syntax that mirrors the construction of array andġ / 2 // 0.5 1 / 2 = 1.0 / 2.0 // this is true
z += x *= y is equivalent to z += (x *= y) or. w = z = x = y is equivalent to w = (z = (x = y)) or. When chaining these expressions, each assignment is evaluated Note that the return values are always based on the operands’ values before Logical operation without the assignment, so x & y, (x ||= y), and (x ?= y), the return value is that of the In the case of logical assignments, (x &= y), (x **= y) returns the resulting power x ** y, and so on. Y, (x += y) returns the resulting sum x + y, The return value matches the expression to the right of the = sign in the assigning the expression or logging it:Ĭonst z = (x = y) // Or equivalently: const z = x = y Ĭonsole.log(z) // Log the return value of the assignment x = y.Ĭonsole.log(x = y) // Or log the return value directly. Like most expressions, assignments like x = y have a return value. There are also compound assignment operators that are shorthand for the operations The value of its right operand to its left operand. The simple assignment operator is equal ( =), which assigns An assignment operator assigns a value to its left operand based on the value of its