Arithmetic operators
Perform mathematical calculations on numbers.| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 5 + 3 | 8 |
- | Subtraction | 10 - 4 | 6 |
* | Multiplication | 6 * 7 | 42 |
/ | Division | 15 / 3 | 5 |
% | Modulo (remainder) | 17 % 5 | 2 |
^ | Power | 2 ^ 10 | 1024 |
Operator precedence
Operations follow standard mathematical precedence:^(power)*,/,%(multiply, divide, modulo)+,-(add, subtract)
Comparison operators
Compare values and return boolean results.| Operator | Name | Example | Result |
|---|---|---|---|
== | Equal | 5 == 5 | true |
!= | Not equal | 5 != 3 | true |
> | Greater than | 10 > 5 | true |
< | Less than | 3 < 10 | true |
>= | Greater or equal | 5 >= 5 | true |
<= | Less or equal | 3 <= 5 | true |
Logical operators
Combine boolean conditions.| Operator | Name | Example | Result |
|---|---|---|---|
and | Logical AND | true and false | false |
or | Logical OR | true or false | true |
not | Logical NOT | not true | false |
Short-circuit evaluation
Logical operators stop early when the result is determined:Ternary operator
Conditionally return one of two values.Null coalescing operator
Return the first non-null value.Membership operators
Check if a value exists in a collection or range.In operator
Not in operator
Negate membership tests:String operators
Concatenation
The+ operator joins strings:
Template strings
Embed expressions in strings:Array operators
Index access
Object operators
Property access
Optional chaining
Access nested properties is optional:Operator precedence table
From highest to lowest precedence:| Precedence | Operators |
|---|---|
| 1 | () (grouping) |
| 2 | ., [] (property access) |
| 3 | +, - (unary) |
| 4 | ?? (null coalescing) |
| 5 | ^ (power, right-associative) |
| 6 | *, /, % |
| 7 | not (unary) |
| 8 | +, - (binary) |
| 9 | ==, !=, <, >, <=, >=, in, not in |
| 10 | and |
| 11 | or |
| 12 | ? : (ternary) |