← Back to lessons

2 Constants

Beginner

In Cangjie, variable definition uses the following structure: Modifier Variable name: Variable type = Initial value

Mutability modifiers: let and var, which correspond to the immutable and mutable attributes, respectively. Mutability determines whether the value of a variable can be modified after initialization.

Constants.cj
import std.math.*

let s: String = "constant"

main() {
    println(s)
    // Type definition is not necessary here as it can be inferred
    let n: Int64 = 500000000

    // Statically typed, need to cast int to float for interoperability
    let d = 3e20 / Float64(n)

    println("${n} ${d}")

    // sin does not work with Int
    println(sin(Float64(n)))

}