type()
The type() built-in function returns the type of a value as a string. Useful for debugging, type checking, and conditional logic.
Syntax
type(value)Return values
| Value type | Returns |
|---|---|
| Integer | "int" |
| Float | "float" |
| String | "string" |
| Boolean | "bool" |
| Array | "array" |
| Object | "object" |
| Void | "void" |
Examples
let x = 42;
let y = 3.14;
let s = "hello";
let b = true;
let arr = [1, 2, 3];
print(type(x)); // "int"
print(type(y)); // "float"
print(type(s)); // "string"
print(type(b)); // "bool"
print(type(arr)); // "array"
let obj = new Point();
print(type(obj)); // "object"Use case: Type checking
fn process(value) {
if (type(value) == "array") {
print("Processing array of length", len(value));
} else {
print("Processing single value:", value);
}
}