JavaScript Operators Reference
Complete Operators Reference
Revised July 2025
Type | Common Use | Example |
---|---|---|
Assignment | Assigns a value to a variable | x = 5 |
Arithmetic | Performs arithmetic between variables | x = y + 2 |
String | Concatenates (adds) strings | "Sun" + "shine" |
Exponentiation | Raises a variable to a power | x++ |
Remainder | Returns the remainder from a division | x++ |
Increment | Increments a variable | x++ |
Decrement | Decrements a variable | x-- |
Comparison | Compares variables | (x == 5) |
Logical | Detefines the logic between variables | (x>0 || x>0) |
Bitwise | Does binary operations on numbers | (5 & 1) |
Spread | Spreads an array into individual values | (...numbers) |
Relational | Returns if a variable is a propery | "age" in person |
typeof | Returns the type of a variable | typeof "John" |
instanceof | Returns if a variable is an object | x instance of Array |
delete | Deletes an object property | delete car.color |
void | Retuns undefined | void(0) |
JavaScript Assignment Operators
Assignment operators are used to assign values to JavaScript variables.
Given that x = 10 and y = 5, the table below explains the assignment operators:
Oper | Example | Same As | Result | Try it |
---|---|---|---|---|
= | x = y | x = y | x = 5 | Try it » |
+= | x += y | x = x + y | x = 15 | Try it » |
-= | x -= y | x = x - y | x = 5 | Try it » |
*= | x *= y | x = x * y | x = 50 | Try it » |
/= | x /= y | x = x / y | x = 2 | Try it » |
%= | x %= y | x = x % y | x = 0 | Try it » |
: | x: 45 | size.x = 45 | x = 45 | Try it » |
Study our JavaScript Assignment Tutorial.
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic between variables and/or values.
Given that y = 5, the table below explains the arithmetic operators:
Oper | Name | Example | Results | Try it |
---|---|---|---|---|
+ | Addition | x = y + 2 | y=5, x=7 | Try it » |
++ | Increment | x = y++ | y=6, x=5 | Try it » |
++ | Increment | x = ++y | y=6, x=6 | Try it » |
- | Subtraction | x = y - 2 | y=5, x=3 | Try it » |
-- | Decrement | x = y-- | y=4, x=5 | Try it » |
-- | Decrement | x = --y | y=4, x=4 | Try it » |
* | Multiplication | x=y*2 | y=5, x=10 | Try it » |
** | Exponentiation | x = y ** 2 | y=5, x=25 | Try it » |
/ | Division | x = y / 2 | y=5, x=2.5 | Try it » |
% | Remainder | x = y % 2 | y=5, x=1 | Try it » |
Study our JavaScript Arithmetic Tutorial.
Conditional (Ternary) Operator
The conditional operator assigns a value to a variable based on a condition.
Syntax | Example | Try it |
---|---|---|
(condition) ? x : y | (z < 18) ? x : y | Try it » |
JavaScript String Operators
The + operator, and the += operator can also be used to concatenate (add) strings.
Given that t1 = "Good ", t2 = "Morning", and t3 = "", the table below explains the operators:
Oper | Example | t1 | t2 | t3 | Try it |
---|---|---|---|---|---|
+ | t3 = t1 + t2 | "Good " | "Morning" | "Good Morning" | Try it » |
+= | t1 += t2 | "Good Morning" | "Morning" | Try it » |
Study our JavaScript Strings Tutorial.
Javascript Comparison Operators
Comparison operators are used in logical statements to determine equality or difference between variables or values.
Given that x = 5, the table below explains the comparison operators:
Oper | Name | Comparing | Returns | Try it |
---|---|---|---|---|
== | equal to | x == 8 | false | Try it » |
== | equal to | x == 5 | true | Try it » |
=== | equal value and type | x === "5" | false | Try it » |
=== | equal value and type | x === 5 | true | Try it » |
!= | not equal | x != 8 | true | Try it » |
!== | not equal value or type | x !== "5" | true | Try it » |
!== | not equal value or type | x !== 5 | false | Try it » |
> | greater than | x > 8 | false | Try it » |
< | less than | x < 8 | true | Try it » |
>= | greater or equal to | x >= 8 | false | Try it » |
<= | less or equal to | x <= 8 | true | Try it » |
Study our JavaScript Comparisons Tutorial.
JavaScript Logical Operators
Logical operators are used to determine the logic between variables or values.
Given that x = 6 and y = 3, the table below explains the logical operators:
Oper | Name | Example | Try it |
---|---|---|---|
&& | AND | (x < 10 && y > 1) is true | Try it » |
|| | OR | (x === 5 || y === 5) is false | Try it » |
! | NOT | !(x === y) is true | Try it » |
JavaScript Bitwise Operators
Bit operators work on 32 bits numbers. Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.
Oper | Name | Example | Same as | Result | Dec | Try it |
---|---|---|---|---|---|---|
& | AND | x = 5 & 1 | 0101 & 0001 | 0001 | 1 | Try it » |
| | OR | x = 5 | 1 | 0101 | 0001 | 0101 | 5 | Try it » |
~ | NOT | x = ~ 5 | ~0101 | 1010 | 10 | Try it » |
^ | XOR | x = 5 ^ 1 | 0101 ^ 0001 | 0100 | 4 | Try it » |
<< | Left shift | x = 5 << 1 | 0101 << 1 | 1010 | 10 | Try it » |
>> | Right shift | x = 5 >> 1 | 0101 >> 1 | 0010 | 2 | Try it » |
>>> | Unsigned right | x = 5 >>> 1 | 0101 >>> 1 | 0010 | 2 | Try it » |
Study our JavaScript Bitwise Tutorial.