// normal variablevar num1 = 1// multiple variablesvar num1, num2// multiple variables with valuevar num2 = 2, num3 = 3// multiple variables with diferent typevar num4: int = 4, say: str = "string"
Constants
// normal constantconst num1 = 1// multiple constants (initial value is required)const num1: int = 1, num2: int = 2// multiple constants with diferent typeconst num3: int = 3, say: str = "string"
Tuple
// normal tuplevar tuple = (1, "Hello", true)// tuple with typevar tuple: tuple<int, str> = (1, "Hello")// tuple with other type declaration (recomended)var otherTuple: (int, str) = (1, "Hello")
Objects
// normal objectvar obj = { name: "John", age: 20}// object with typevar obj: object = { name: "John", age: 20}// object with other type declaration (recomended)interface Person { name: str, age: int}var otherObj: Person = { name: "John", age: 20}// object with mixed typesvar obj: object = { name: "John", age: 20, sayHello: fn(): void -> print("Hello")}// object with mixed types (recomended)interface Person { name: str, age: int, sayHello: () -> void}var otherObj: Person = { name: "John", age: 20, sayHello: fn(): void -> print("Hello")}
Lists
// normal listvar list = [1, 2, 3]// list with typevar listOfStrings: list<str> = ["Hello", "World"]// list with other type declaration (recomended)var otherListOfStrings: srt[] = ["Hello", "World"]// list with mixed typesvar mixedList: list<any> = ["Hello", 1, true]// list with mixed types (recomended)var otherMixedList: any[] = ["Hello", 1, true]// list with multiple typesvar multipleTypesList: list<int, str, bool> = [1, "Hello", true]// list with multiple types (recomended)var otherMultipleTypesList: (int, str, bool)[] = [1, "Hello", true]
Functions
// normal functionfn sayHello() { print("Hello")}// function with parametersfn sayHello(name: str) { print("Hello " + name)}// function with returnfn sayHello(name: str): str { return "Hello " + name}// function with parameters and returnfn sayHello(name: str, age: int): str { return "Hello " + name + ", you are " + age + " years old"}
Arrow Functions
// normal arrow function (single line)var sayHello = (): void -> print("Hello")// normal arrow function (multiple lines)var sayHello = (): void -> { print("Hello") print("World")}// anonymous functionconst pet = { getName: fn(): str { return "Dog" }}// anonymous arrow functionconst person = { getAge: (): int -> 20}// async/await is supported by default!!!// anonymous async functionconst pet = { getName: fn(): str { await sleep(1000) return "Dog" }}// anonymous async arrow functionconst person = { getAge: (): int -> { await sleep(1000) return 20 }}// method styleconst person = { getAge (): int { return 20 }}
Classes
Basic class
class Person { // constructor constructor(name: str, age: int) { this.name = name this.age = age } // method sayHello () { print("Hello " + this.name + ", you are " + this.age + " years old") }}// create objectvar person = new Person("John", 20)// with named parametersvar person = new Person(name: "John", age: 20)