Variables
Declare and use variables in Unnarize.
Declaration
Use the var keyword to declare variables:
var name = "Unnarize";
var count = 42;
var price = 19.99;
var active = true;
Data Types
| Type | Example | Description |
|---|---|---|
| Integer | 42, -10 |
Whole numbers |
| Float | 3.14, -0.5 |
Decimal numbers |
| String | "hello" |
Text values |
| Boolean | true, false |
Logical values |
Reassignment
Variables can be reassigned to new values:
var x = 10;
x = 20; // x is now 20
x = "text"; // dynamic typing allowed
String Concatenation
Use + to concatenate strings and values:
var name = "Alice";
var age = 25;
print("Name: " + name); // Name: Alice
print("Age: " + age); // Age: 25
Scope
Variables have lexical scope:
var global = "I am global";
function test() {
var local = "I am local";
print(global); // Works
print(local); // Works
}
print(global); // Works
// print(local); // Error: local is out of scope