Operators

Mathematical operators

Operator

Description

Examples

+

Addition

+4 +z 2 + 3 a + b

-

Subtraction

-4 -b 2 - 5 x - y

**

Exponentiation

2 ** 3 a ** b

*

Multiplication

2 * 3 a * b

/

Division

2 / 3 a / b

%

Modulo

2 % 3 a % b

++

Increment

++a b++

--

Decrement

--a b--

// todo

Increment and decrement support both prefix and postfix on mutable targets

  • Variables

  • Members

  • Indexers

a++
++x.z
arr[n]--

Relational operators

Operator

Description

Examples

<

Less than

a < b

<=

Less than oe equal

a <= b

>

Greater than

a > b

>=

Greater than or equal

a >= b

==

Equal to

a == b

!=

Not equal

a != b

~=

Same to

a ~= b

Less/greater than or equal comparison operators will convert the operands value to number implicitly.

== for strong typed comparison, while ~= converts to the same type.

Logical operators

Operator

Description

Examples

!

Logical NOT

!true !x

&&

Logical AND

true && false a && b

||

Logical OR

true || false a || b

! always gives a Boolean value.

While && and || return the value of the operand, depends on the logic.

In logical AND oprator, the right operand will not executed if the left operand is false.

In logical OR oprator, the right operand will not executed if the left operand is true.

String concatenation

The operator .. supports you to concatenate two values.

If an operand is not string, it will be converted into string implicitly.

Bitwise operators

Operator

Description

Examples

~

Bitwise NOT

~5 ~n

|

Bitwise OR

4 | 5 x | y

&

Bitwise AND

4 & 5 x & y

^

Bitwise XOR

4 ^ 5 x ^ y

<<

Shift left

a << b x << 2

>>

Right shift

a >> b x >> 2

>>>

Unsigned right shift

a >>> b x >>> 2

// todo

All bitwise operators will cast your value to integer number implicitly.

Assignments

// todo

Precedence

Precedence

Associativity

. [] () ?.

++ -- (suffix)

Left-to-right

typeof ! - ~ (unary)

++ -- (prefix)

Right-to-left

**

Left-to-right

% * /

Left-to-right

+ -

Left-to-right

<< >>

Left-to-right

< <= > >=

Left-to-right

!=

Left-to-right

==

Left-to-right

&

Left-to-right

^

Left-to-right

|

Left-to-right

&&

Left-to-right

||

Left-to-right

? : (ternary)

Right-to-left

=

+= -= *= /=

^= &= |= >>= <<=

Right-to-left

Last updated

Was this helpful?