Every value has an inherent boolean interpretation used in if, while, and logical operators.
| Value | Truthy? |
|---|---|
null |
false |
false |
false |
0 |
false |
0.0 |
false |
"" (empty string) |
false |
[] (empty list) |
false |
{} (empty map) |
false |
| Any other value | true |
let items = []
if items {
print("Has items")
} else {
print("Empty list") // this branch executes
}
let config = {}
if not config {
print("Config is empty") // executes
}