Skip to main content

Operators

Skittles supports the subset of standard TypeScript operators listed below. They work exactly as you'd expect and compile to their Solidity equivalents where supported.

Arithmetic Operators

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Moduloa % b
**Exponentiationa ** b
class Math {
public add(a: number, b: number): number {
return a + b;
}

public power(base: number, exp: number): number {
return base ** exp;
}
}
note

Division is integer division — 7 / 2 gives 3, not 3.5. Solidity does not support floating-point numbers.

Comparison Operators

OperatorDescriptionExample
==Equala == b
!=Not equala != b
>Greater thana > b
<Less thana < b
>=Greater than or equala >= b
<=Less than or equala <= b
===Strict equala === b
!==Strict not equala !== b
class Comparison {
public isGreater(a: number, b: number): boolean {
return a > b;
}

public isEqual(a: number, b: number): boolean {
return a === b;
}
}
note

=== and !== compile to == and != in Solidity. Solidity has no strict equality distinction, so both forms behave identically.

Logical Operators

OperatorDescriptionExample
&&Logical ANDa && b
||Logical ORa || b
!Logical NOT!a
class Access {
owner: address;
active: boolean = true;

public canAccess(caller: address): boolean {
return caller == this.owner && this.active;
}

public isRestricted(): boolean {
return !this.active;
}
}

Nullish Coalescing and Optional Chaining

OperatorDescriptionExample
??Nullish coalescinga ?? b
?.Optional chaininga?.b
class Fallback {
balances: Map<address, number> = new Map();

public getBalanceOrDefault(account: address): number {
return this.balances[account] ?? 0;
}
}
note

Since Solidity has no null or undefined, ?? checks for the zero value of the type. x ?? y compiles to (x == 0) ? y : x. Optional chaining (?.) compiles to regular property access since all Solidity values are non-nullable.

Compound Assignment Operators

OperatorDescriptionEquivalent
+=Add and assigna = a + b
-=Subtract and assigna = a - b
*=Multiply and assigna = a * b
/=Divide and assigna = a / b
%=Modulo and assigna = a % b
**=Exponentiate and assigna = a ** b
class Counter {
count: number = 0;

public increment(amount: number): void {
this.count += amount;
}

public halve(): void {
this.count /= 2;
}
}
note

**= is desugared to x = x ** y because Solidity does not have a **= operator.

Increment / Decrement Operators

OperatorDescriptionExample
++Increment by 1a++
--Decrement by 1a--
class Counter {
count: number = 0;

public increment(): void {
this.count++;
}

public decrement(): void {
this.count--;
}
}

Unary Operators

OperatorDescriptionExample
-Negation-a
+Unary plus+a

Bitwise Operators

OperatorDescriptionExample
&Bitwise ANDa & b
|Bitwise ORa | b
^Bitwise XORa ^ b
~Bitwise NOT~a
<<Left shifta << b
>>Right shifta >> b

Bitwise assignment variants are also supported:

OperatorDescriptionEquivalent
&=Bitwise AND assigna = a & b
|=Bitwise OR assigna = a | b
^=Bitwise XOR assigna = a ^ b
<<=Left shift assigna = a << b
>>=Right shift assigna = a >> b
class Flags {
flags: number = 0;

public setFlag(bit: number): void {
this.flags |= (1 << bit);
}

public clearFlag(bit: number): void {
this.flags &= ~(1 << bit);
}

public hasFlag(bit: number): boolean {
return (this.flags & (1 << bit)) != 0;
}
}

Operator Summary

Here's a quick reference of all supported operators grouped by category:

CategoryOperators
Arithmetic+ - * / % **
Comparison== != > < >= <= === !==
Logical&& || !
Nullish?? ?.
Compound Assignment+= -= *= /= %= **=
Increment/Decrement++ --
Unary- +
Bitwise& | ^ ~ << >>
Bitwise Assignment&= |= ^= <<= >>=