JavaScript Operators Overview
JavaScript operators allow you to perform calculations, manipulate data, compare values, and more within your scripts.
Arithmetic Operators
| Operator | Description | Example |
|---|---|---|
| + | Addition | 5 + 3 returns 8 |
| - | Subtraction | 5 - 3 returns 2 |
| * | Multiplication | 5 * 3 returns 15 |
| / | Division | 5 / 3 returns 1.6667 |
| % | Modulus (Remainder) | 5 % 3 returns 2 |
| ** | Exponentiation | 5 ** 3 returns 125 |
Assignment Operators
| Operator | Description | Example |
|---|---|---|
| = | Assign value | x = 5 assigns the value 5 to variable x |
| += | Add and assign | x += 5 is equivalent to x = x + 5 |
| -= | Subtract and assign | x -= 5 is equivalent to x = x - 5 |
| *= | Multiply and assign | x *= 5 is equivalent to x = x * 5 |
| /= | Divide and assign | x /= 5 is equivalent to x = x / 5 |
Comparison Operators
| Operator | Description | Example |
|---|---|---|
| == | Equal to | 5 == 3 returns false |
| != | Not equal to | 5 != 3 returns true |
| > | Greater than | 5 > 3 returns true |
| < | Less than | 5 < 3 returns false |
| >= | Greater than or equal to | 5 >= 3 returns true |
| <= | Less than or equal to | 5 <= 3 returns false |
Logical Operators
| Operator | Description | Example |
|---|---|---|
| && | Logical AND | (x > 5 && y < 10) returns true if both conditions are true |
| || | Logical OR | (x > 5 || y < 10) returns true if either condition is true |
| ! | Logical NOT | !(x > 5) returns false if x is greater than 5 |