Variables

Variables in Caboose.

Variables consist of many data types:

Type

Example

string

"hello", 'world'

number

100, 1.0

nil

nil

bool

true, false

list

["hello", 1, true, nil]

dict

{"hello": 1, "world": false}

Variable Assignment

In Caboose the syntax for variable assignment is var <identifier> = <value>;, where <identifier> is a name containing only alphabetical characters and underscores, and <value> is a valid data type.

Once you have defined a variable, you no longer need to use the var keyword to update it. Variables can also change their type at runtime.

Examples

example_variable_assignment.cb
example_variable_reassignment.cb
example_variable_type_change.cb
var someNumber = 10;
var someString = "hello";
var someOtherString = 'hello';
var someBoolean = true;
var someFalseBoolean = false;
var someNilValue = nil;
var someOtherNilValue; // Variables declared without a value are set to nil
var someList = [1, 2, "hi", 'hi', nil, true, false]; // Lists can hold any value
var someDict = {"key": 10, "key1": true, "key2": [1, "2", false], "key3": {"1": 2}}; // Dictionaries must have a string key, but can hold any value
var someNumber = 10;
‚Äč
someNumber = someNumber + 1;
var someVariable = 10;
someVariable = "Some text"; // This is perfectly valid