Skip to main content

Operators

This language supports various operators, categorized into different types based on their usage and behavior.

Arithmetic Operators

Operator (token)DescriptionExample
+Addition (numbers) / Concatenation (strings)5 + 38, "a" + "b""ab"
-Subtraction10 - 46
*Multiplication6 * 212
/Division9 / 33
%Remainder (modulo)10 % 31

Assignment Operators

Operator (token)DescriptionExample
=Assignmentx = 10
+=Add and assignx += 2x = x + 2
-=Subtract and assignx -= 2x = x - 2
*=Multiply and assignx *= 2x = x * 2
/=Divide and assignx /= 2x = x / 2
%=Modulo and assignx %= 3x = x % 3
&=Bitwise AND and assignx &= 3x = x & 3
|=Bitwise OR and assignx |= 3x = x | 3
^=Bitwise XOR and assignx ^= 3x = x ^ 3
<<=Left shift and assignx <<= 1x = x << 1
>>=Right shift and assignx >>= 1x = x >> 1
<=>Swapx <=> y

Comparison Operators

Operator (token)DescriptionExample
==Equality (value)5 == 5.0true
!=Inequality (value)5 != 5.0false
===Strict equality (value and type)5 === 5ufalse
!==Strict inequality (value and type)5 !== 5utrue
>Greater than10 > 5true
<Less than3 < 7true
>=Greater than or equal to5 >= 5true
<=Less than or equal to4 <= 5true

Logical Operators

Operator (token)DescriptionExample
&&Logical ANDtrue && falsefalse
||Logical ORtrue || falsetrue

Bitwise Operators

Operator (token)DescriptionExample
&Bitwise AND5 & 31
|Bitwise OR5 | 37
^Bitwise XOR5 ^ 36
~Bitwise NOT~5-6
<<Left shift5 << 110
>>Right shift5 >> 12

Unary Operators

Operator (token)DescriptionExample
-Unary negation-5-5
!Logical NOT!truefalse
~Bitwise NOT~5-6
typeofType checkingtypeof 123"int"
tostringValue to stringtostring 20.2"20.2"

Postfix Operators

Operator (token)DescriptionExample
++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 callcallable()
[]Array / object property accessarr[0]
.Property accessobj.prop

Prefix Operators

Operator (token)DescriptionExample
++Pre-increment (increments, then returns value)let x = 5; ++x6
--Pre-decrement (decrements, then returns value)let x = 5; --x4

Miscellaneous Operators

Operator (token)DescriptionExample
,Comma operator (evaluates multiple expressions)(a = 1, b = 2, a + b)3
?:Ternary operator5 > 3 ? "yes" : "no"yes