Variables & Lexical Scope
In Djazair, variables are declared using the let keyword. The language uses dynamic typing with lexical block scoping.
Declaring Variables
Variables are declared using let followed by an identifier and an optional initial value:
djazair
let name = "Djazair"
let version = 1.1
let isReleased = True
# Numbers can include underscores for readability
let largeCount = 100_000_000
let hexNumber = 0xFF
Reassignment & Mutation
Once declared with let, variables can be reassigned to values of any type, or mutated using shorthand assignment operators:
djazair
let score = 10
score += 5 # score is now 15
score *= 2 # score is now 30
score++ # score is now 31
# Changing types dynamically
score = "Thirty-One" # Valid dynamic typing
Lexical Block Scoping
Djazair follows strict lexical block scoping. Any variable declared inside a block (such as an if, while, for, or fn block) is isolated to that block and shadows any identical outer identifier:
djazair
let count = 100
if True
let count = 50 # Shadows the outer count
print("Inner count: ${count}") # => Inner count: 50
end
print("Outer count: ${count}") # => Outer count: 100
Identifier Naming Rules
- Identifiers can start with any ASCII letter (
a-z,A-Z), underscore (_), or any valid Unicode letter (including Arabic letters likeع,س). - Subsequent characters may include digits (
0-9) and emojis (e.g.let 🚀_speed = 300). - Keywords such as
let,fn,class,if, andwhilecannot be used as variable names.