This language supports various operators, categorized into different types based on their usage and behavior.
Arithmetic Operators
Operator (token) | Description | Example |
---|
+ | Addition (numbers) / Concatenation (strings) | 5 + 3 → 8 , "a" + "b" → "ab" |
- | Subtraction | 10 - 4 → 6 |
* | Multiplication | 6 * 2 → 12 |
/ | Division | 9 / 3 → 3 |
% | Remainder (modulo) | 10 % 3 → 1 |
Assignment Operators
Operator (token) | Description | Example |
---|
= | Assignment | x = 10 |
+= | Add and assign | x += 2 → x = x + 2 |
-= | Subtract and assign | x -= 2 → x = x - 2 |
*= | Multiply and assign | x *= 2 → x = x * 2 |
/= | Divide and assign | x /= 2 → x = x / 2 |
%= | Modulo and assign | x %= 3 → x = x % 3 |
&= | Bitwise AND and assign | x &= 3 → x = x & 3 |
|= | Bitwise OR and assign | x |= 3 → x = x | 3 |
^= | Bitwise XOR and assign | x ^= 3 → x = x ^ 3 |
<<= | Left shift and assign | x <<= 1 → x = x << 1 |
>>= | Right shift and assign | x >>= 1 → x = x >> 1 |
<=> | Swap | x <=> y |
Comparison Operators
Operator (token) | Description | Example |
---|
== | Equality (value) | 5 == 5.0 → true |
!= | Inequality (value) | 5 != 5.0 → false |
=== | Strict equality (value and type) | 5 === 5u → false |
!== | Strict inequality (value and type) | 5 !== 5u → true |
> | Greater than | 10 > 5 → true |
< | Less than | 3 < 7 → true |
>= | Greater than or equal to | 5 >= 5 → true |
<= | Less than or equal to | 4 <= 5 → true |
Logical Operators
Operator (token) | Description | Example |
---|
&& | Logical AND | true && false → false |
|| | Logical OR | true || false → true |
Bitwise Operators
Operator (token) | Description | Example |
---|
& | Bitwise AND | 5 & 3 → 1 |
| | Bitwise OR | 5 | 3 → 7 |
^ | Bitwise XOR | 5 ^ 3 → 6 |
~ | Bitwise NOT | ~5 → -6 |
<< | Left shift | 5 << 1 → 10 |
>> | Right shift | 5 >> 1 → 2 |
Unary Operators
Operator (token) | Description | Example |
---|
- | Unary negation | -5 → -5 |
! | Logical NOT | !true → false |
~ | Bitwise NOT | ~5 → -6 |
typeof | Type checking | typeof 123 → "int" |
tostring | Value to string | tostring 20.2 → "20.2" |
Postfix Operators
Operator (token) | Description | Example |
---|
++ | Post-increment (returns value, then increments) | let x = 5; x++ → 5 (then x is 6 ) |
-- | Post-decrement (returns value, then decrements) | let x = 5; x-- → 5 (then x is 4 ) |
() | Function call | callable() |
[] | Array / object property access | arr[0] |
. | Property access | obj.prop |
Prefix Operators
Operator (token) | Description | Example |
---|
++ | Pre-increment (increments, then returns value) | let x = 5; ++x → 6 |
-- | Pre-decrement (decrements, then returns value) | let x = 5; --x → 4 |
Miscellaneous Operators
Operator (token) | Description | Example |
---|
, | Comma operator (evaluates multiple expressions) | (a = 1, b = 2, a + b) → 3 |
?: | Ternary operator | 5 > 3 ? "yes" : "no" → yes |