Defining Variables
variable = 10greeting = "hello"
def showGreeting() (
log greeting
)
showGreeting()
// helloany count = 1
def increment() (
any count = 10
count += 1
log count
)
increment()
log count
// 11
// 1Last updated
Use name = value to create or update an untyped variable.
variable = 10Top-level variables are global and can be read inside functions:
greeting = "hello"
def showGreeting() (
log greeting
)
showGreeting()
// helloInside a function or block, declare local variables with a type keyword or auto. Local variables shadow globals with the same name and do not leak out of the function.
any count = 1
def increment() (
any count = 10
count += 1
log count
)
increment()
log count
// 11
// 1Variables must be assigned or declared before they are read. Referencing an undefined variable is an error in current OSL.
Last updated