Binding Values in Variables
Explore how to bind values to variables in Elixir, use these variables in mathematical expressions, and understand the importance of clear variable naming. This lesson helps you write more readable and maintainable functional code by following Elixir community naming conventions.
We'll cover the following...
Variables
Variables are containers that hold values. Suppose you have a friend who works with office facilities, and they organize the office tools by putting them in boxes. They put a label on boxes to help workers know what’s inside without opening them. Variables are like that; we can’t see what’s inside without checking, but the variable’s name can give us a hint. Let’s create a variable using IEx:
iex> x = 42
#Output -> 42
iex> x
#Output -> 42
IEx shell is present at the end of the lesson to try out the different examples.
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 ...