Skip to content

Variables and Types

Variables in Stellartrails are declared using the let keyword. Types are inferred, but you can specify them explicitly for supported types.

let x = 42        # inferred as Int
let y = 3.14      # inferred as Float
let z = true      # inferred as Bool
let s = "hello"   # inferred as String
let a: Int = 1    # explicit type
let b: Float = 2.0
let c: Bool = false
let d: String = "str"

You can also declare and use functions with typed parameters and return values:

fn add(a: Int, b: Int) -> Int {
    return a + b
}
let sum = add(2, 3)
print(sum)

Next

Up