JavaScript has several types of operators including:
Arithmetic operators
These operators perform mathematical operations such as:
- + : Addition
- - : Subtraction
- * : Multiplication
- ** : Exponentiation (ES2016)
- / : Division
- % : Modulus (Division Remainder)
- ++ : Increment
- -- : Decrement
Comparison operators
These operators compare values and return a Boolean value (true or false) such as:
- == : 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
Logical operators
These operators perform logical operations such as:
- && : logical and
- || : logical or
- ! : logical not
Assignment operators
These operators assign a value to a variable such as:
- = : Example : x = y this is the same as: x = y
- += : Example : x += y this is the same as: x = x + y
- -= : Example : x -= y this is the same as: x = x - y
- *= : Example : x *= y this is the same as: x = x * y
- /= : Example : x /= y this is the same as: x = x / y
- %= : Example : x %= y this is the same as: x = x % y
- **= : Example : x **= y this is the same as: x = x ** y
Ternary operator
Conditional operator ( a?b:c ).
Unary operators
This operators perform actions on only one operand, like increment ++ and decrement -- operator, typeof, delete, etc.
Bitwise operator
These operators perform bitwise operations, such as:
- & : AND
- | : OR
- ~ : NOT
- ^ : XOR
- << : left shift
- >> : right shift
- >>> : unsigned right shift
Spread operator
The spread operator allows an iterable such as an array to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected.
Destructuring operator
The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.