JavaScript Operators Reference
JavaScript Operators
JavaScript Operators are used to assign values, compare values, perform arithmetic operations, and more.
Type | Common Use | Example |
---|---|---|
Assignment | Assigns a value to a variable | x = 5 |
Arithmetic | Performs arithmetic between variables | x = y + 2 |
String | Concatenates (add) 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) |
Some Examples
Operator | Name | Example | |
---|---|---|---|
= | Assign | x = 5 | Try it » |
+ | Addition | x = y + 2 | Try it » |
* | Multiplication | x = y * 2 | Try it » |
!= | Equal to | x == 8 | Try it » |
> | Greater than | x > 8 | Try it » |
|| | OR | (x > 0 || x > 0) | Try it » |