An arithmetic operator accepts numerical values as operands (either literals or variables) and returns a single numerical value. Addition (+), subtraction (-), multiplication (*), and division (/) are the standard arithmetic operators. When used with floating point numbers, these operators behave similarly to those used in most other programming languages (in particular, note that division by zero produces Infinity).
|+||Addition||The addition operator computes the numerical sum of two numeric operands. It also joins two strings or numbers.|
|-||Subtraction||The subtraction operator returns the numerical value of the difference between two operands.|
|*||Multiplication||The multiplication operator returns the product of two operands, one multiplicand and one multiplier.|
|/||Division||The division operator returns the quotient of its operands, where the divisor is on the right and the dividend is on the left.|
|%||Modulus (Remainder)||When a dividend is divided by a divisor, the modulus operator yields the remainder. The residual operator is another name for the modulus operator. It adopts the dividend symbol.|
|**||Exponentiation (ES2016)||The result of the exponentiation operator is to raise the first operand to the power of the second operand. Exponentiation is a right-associative operator.|
|++||Increment||The increment operator increases its operand and returns a value.|
|--||Decrement||The decrement operator decrements its operand (subtracts one from it) and returns a value.|
|-||Unary||This is a unary operator, which means it only has one operand. It returns the inverse of an operand.|
|+||Unary||This is a method for converting a non-number to a number. Although unary negation (-) can also convert non-numbers, unary plus is the quickest and most preferred method of converting something into a number because it does not perform any additional operations on the number.|
The equal (=) operator assigns the value of the right-hand operand to the left-hand operand. If a = b, the value of b is assigned to a.
A variable is assigned a value using the simple assignment operator. The assigned value is evaluated by the assignment process. It is possible to chain the assignment operator to assign a single value to multiple variables.
|a+=b||a=a+b||Addition||This operator adds the right operand's value to a variable and assigns the result to the variable. The behavior of the addition assignment operator is determined on the types of the two operands. It is possible to add or concatenate. If concatenation is used, the string is used as an operand.|
|a-=b||a=a-b||Subtraction||Subtracts the right operand's value from a variable and assigns the result to the variable.|
|a*=b||a=a*b||Multiplication||This operator multiplies the value of the right operand by a variable and assigns the result to the variable.|
|a/=b||a=a/b||Division||This operator divides a variable by the right operand's value and assigns the result to the variable.|
|a%=b||a=a%b||Remainder||This operator divides a variable by the right operand's value and assigns the remainder to the variable.|
|a**=b||a=a**b||Exponentiation||This operator elevates a variable's value to the power of the argument on the right.|
|a<<=b||a=a<<b||Left Shift||This operator shifts the number of bits supplied to the left and assigns the result to the variable.|
|a>>=b||a=a>>b||Right Shift||This operator shifts the number of bits supplied to the right and assigns the result to the variable.|
|a&=b||a=a&b||Bitwise AND||This operator takes the binary representations of both operands and performs a bitwise AND operation on them before assigning the result to a variable.|
|a|=b||a=a|b||Bitwise OR||This operator takes both operands' binary representations, performs a bitwise OR operation on them, and assigns the result to a variable.|
|a^=b||a=a^b||Bitwise XOR||This operator takes both operands' binary representations, performs a bitwise XOR operation on them, and assigns the result to the variable.|
In addition to the comparison operators that may be used to string values, the concatenation operator (+) joins two string values, yielding another string that is the union of the two operand strings.
|+||Concatenation||str1 + str2||Concatenation of str1 and str2|
|+=||Concatenation assignment||str1 += str2||Appends the str2 to the str1|
Incrementing and Decrementing operator
The increment (++) operator increases its operand (adds one to it) and returns the value before or after the increment, depending on where the operator is inserted.
Depending on where the operator is used, the decrement (--) operator decrements (subtracts one from) its argument and returns the value before or after the decrement.
|++x||Pre-increment||Increments x by one, then returns x|
|x++||Post-increment||Returns x, then increments x by one|
|--x||Pre-decrement||Decrements x by one, then returns x|
|x--||Post-decrement||Returns x, then decrements x by one|
This behavior usually leads to a numerical comparison of the operands. The === and !== operators, which conduct rigorous equality and inequality comparisons, are the only exceptions to type conversion within comparisons. Before testing equality, these operators do not attempt to transform the operands to compatible types.
|==||Equal||x == y||True if x is equal to y|
|===||Identical||x === y||True if x is equal to y, and they are of the same type|
|!=||Not equal||x != y||True if x is not equal to y|
|!==||Not identical||x !== y||True if x is not equal to y, or they are not of the same type|
|<||Less than||x < y||True if x is less than y|
|>||Greater than||x > y||True if x is greater than y|
|>=||Greater than or equal to||x >= y||True if x is greater than or equal to y|
|<=||Less than or equal to||x <= y||True if x is less than or equal to y|
When logical operators are employed with Boolean (logical) values, they yield a Boolean value. However, because the && and || operators return the value of one of the given operands, they may produce a non-Boolean value if used with non-Boolean values. The logical operators are listed in the table below.
|&&||And||x && y||True if both x and y are true|
|||||Or||x || y||True if either x or y is true|
|!||Not||!x||True if x is not true|