Search⌘ K
AI Features

Assignments with the Match Operator

Explore Elixir's unique use of the match operator instead of traditional assignment to bind values in variables. Understand how pattern matching works by practicing examples in IEx, and learn to interpret errors that arise from mismatched patterns.

We'll cover the following...

In most languages, = is the assignment operator. To assign the value 1 to a variable a, depending on the language, we write something like a = 1. The value on the right-hand side is assigned to the variable on the left-hand side.

Examples

But in Elixir, = isn’t the assignment operator but a match operator. Let’s elaborate it first with a ...