Declaration
All variables must be declared with let before use.
let city = "Manila"
let port = 8080
let active = true
let data = null // explicitly null
Optional Type Annotation
A type annotation after : is accepted syntactically but is not enforced at runtime (the language is dynamic). It serves as documentation.
let zone: Subnet = 192.168.1.0/24
let count: Integer = 0
Re-assignment
After declaration, a variable is re-assigned without let:
let score = 0
score = score + 10 // re-assignment
Compound Assignment
Joa supports the common shorthand operators that combine an arithmetic operation with assignment:
| Operator | Equivalent To | Example |
|---|---|---|
+= |
x = x + value |
score += 5 |
-= |
x = x - value |
health -= 10 |
*= |
x = x * value |
total *= 2 |
/= |
x = x / value |
ratio /= 100 |
let score = 10
score += 5 // 15
score *= 2 // 30
score -= 3 // 27
score /= 9 // 3 (integer division)
print(score) // 3
Assignment Errors
Attempting to assign to a name that was never declared with let is a Name Error:
undeclared = 5
// ❌ Name Error: Cannot assign to undefined variable 'undeclared'.
// 💡 Hint: Declare the variable first with: let undeclared = ...