February 2018
Beginner
200 pages
4h 37m
English
Variables are containers that hold values. My friend works with office facilities, and she organizes the office tools by putting them in boxes. She puts a label on boxes to help workers know what’s inside without opening them. Variables are like that; you can’t see what’s inside without checking, but the variable’s name can give you a hint. Let’s create a variable using IEx:
| | iex> x = 42 |
| | 42 |
| | iex> x |
| | 42 |
We’ve used the = operator to assign the name x to the value 42. This action of assigning a name to a value is called binding. We can bind new values and results of expressions in variables. Try it:
| | iex> x = 6 |
| | 6 |
| | iex> x = 7 |
| | 7 |
| | iex> x = 9 + 1 |
| | 10 |
| | iex> x |
| | 10 |
The most interesting part of variables is that ...
Read now
Unlock full access