Variables

Variables in Risor are declared with the let keyword and can be reassigned after declaration. Use const for values that should not change.

Declarations

Use let to declare a new variable and assign it a value:

let name = "Alice"
let x = 42
let active = true

Every variable must be initialized at the point of declaration. There is no uninitialized variable state in Risor.

Constants

Use const to declare a value that cannot be reassigned:

const MAX_RETRIES = 3
const API_VERSION = "v2"

Attempting to reassign a const will produce a compile-time error.

Reassignment

After a variable has been declared, you can reassign it using =:

let x = 42
x = 100

Reassignment does not require the let keyword. Using let again with the same name in the same scope will shadow the previous variable.

Compound Assignment

Risor supports compound assignment operators that combine an arithmetic operation with assignment:

let x = 10
 
x += 5   // x is now 15
x -= 3   // x is now 12
x *= 2   // x is now 24
x /= 4   // x is now 6

The supported compound assignment operators are:

OperatorDescriptionEquivalent
+=Add and assignx = x + y
-=Subtract and assignx = x - y
*=Multiply and assignx = x * y
/=Divide and assignx = x / y

Scope

Variables are scoped to the block in which they are declared. A variable declared inside a function or block is not visible outside of it:

let x = 1
 
function example() {
    let y = 2
    x = 10    // can access outer variable
}
 
// y is not accessible here

Inner scopes can read and modify variables from outer scopes, which is the foundation for closures in Risor.


Risor © 2026 Deep Noodle