Understanding Soul’s dynamic type system and variable declarations
=
name = "Alice" // String age = 25 // Number isStudent = false // Boolean data = null // Null
var
let
const
integer = 100 decimal = 3.14159 scientific = 1.23e-4 calculation = 0.1 + 0.2 // Correctly equals 0.3
message = "Hello, World!" multiline = "Line 1 Line 2"
true
false
isReady = true isComplete = false // Falsy values: false, null, 0, "" // Everything else is truthy
result = null // Null is falsy in conditions if (!result) { print("No result yet") }
value = 42 if (typeof(value) == "number") { print("It's a number!") } // Common type checks isString = typeof("hello") == "string" isBoolean = typeof(true) == "boolean" isNull = value == null
// String to Number age = Number("25") // 25 price = Number("19.99") // 19.99 // Number to String text = String(42) // "42" formatted = String(3.14159) // "3.14159" // Boolean conversion bool1 = Boolean(1) // true bool2 = Boolean("") // false bool3 = Boolean("false") // true (non-empty string)
globalVar = "I'm global" soul myFunction() { localVar = "I'm local" if (true) { blockVar = "I'm in a block" print(globalVar) // ✓ Accessible print(localVar) // ✓ Accessible } print(blockVar) // ✓ Still accessible } print(localVar) // ✗ Error: undefined variable
// Good userName = "Alice" isLoggedIn = true // Avoid u = "Alice" flag = true
// Good - clear intent count = 0 items = [] // Avoid - unclear count = null
Was this page helpful?