Operator | Description |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
** | Exponentiation (ES2016) |
/ | Division |
% | Modulus (Division Remainder) |
++ | Increment |
-- | Decrement |
Addition (+
):
let sum = 5 + 4; // 9
Subtraction (-
):
let difference = 12 - 3; // 9
Multiplication (*
):
let product = 3 * 3; // 9
Division (/
):
let quotient = 81 / 9; // 9
Modulus (%
):
let remainder = 9 % 2; // 1
Operator | Example | Same As |
---|---|---|
= | x = y | x = y |
+= | x += y | x = x + y |
-= | x -= y | x = x - y |
*= | x *= y | x = x * y |
/= | x /= y | x = x / y |
%= | x %= y | x = x % y |
**= | x **= y | x = x ** y |
Assignment (=
):
let x = 9;
Addition Assignment (+=
):
let y = 5;
y += 4; // Equivalent to y = y + 4;
Subtraction Assignment (-=
):
let z = 12;
z -= 3; // Equivalent to z = z - 3;
Operator | Description |
---|---|
== | equal to |
=== | equal value and equal type |
!= | not equal |
!== | not equal value or not equal type |
> | greater than |
< | less than |
>= | greater than or equal to |
<= | less than or equal to |
? | ternary operator |
Equal (==
):
console.log(9 == "9"); // true (loose equality)
Strict Equal (===
):
console.log(9 === "9"); // false (strict equality)
Not Equal (!=
):
console.log(9 != "9"); // false (loose inequality)
Strict Not Equal (!==
):
console.log(9 !== "9"); // true (strict inequality)
Greater Than (>
):
console.log(90 > 9); // true