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

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    // ...

Last updated

Was this helpful?