...

/

Reusing Variable Names

Reusing Variable Names

Learn how variables can be useful.

It’s also important to keep in mind that a name is unique in the sense that the same name can only refer to one value (object) at a time.

If we successively assign different values to the same variable, the latest one will remain. The previous value of the variable is overwritten, like so:

Press + to interact
Ruby
number = 4
number = number * 3
puts number + 2

Line 1 assigns the number 4 to the name number. Line 2 reassigns another object to it. Essentially, the same name is now referring to a different object.

In terms of our ...