Skip to content

Operators

Arithmetic

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo

Works with both number and integer types (i32, u8):

var x:number = 10 + 5 * 2
var y:i32 = 20 % 3

Integer division truncates toward zero. Integer and float types cannot be mixed in arithmetic — see Type System for details.

Comparison

Operator Description
== Equal
!= Not equal
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
if (x == 42) { console.log("match") }
if (x != 0) { console.log("nonzero") }

Comparisons between integer and number types are allowed — the compiler inserts implicit conversion. See Type System.

Logical

Operator Description
&& And
\|\| Or
! Not
if (x > 0 && x < 100) {
    console.log("in range")
}

if (!active) {
    console.log("inactive")
}

String Concatenation

The + operator concatenates strings:

var greeting:string = "hello " + "world"