Variables

Declaration

To declare a variable, we have a var keyword.

// var <name> [= <value>]
var myVar
var a = 10
var b = 50.2
var hello = 'hello'
var alive = true

There are no let or const, so every variable is mutable, except the use statement.

Everything is local

To make variables be more explicit, undefined variables lead to syntax error. You must declare your variables before use them.

a = 10    // Syntax error: undefined variable
puts b    // ...

There are no global variables, see module Global to store data globally.

Last updated

Was this helpful?