Lesson 2 of 16

Variables & Atoms

Variables

In Elixir, you bind values to names using =. Variables start with a lowercase letter.

name = "Alice"
age = 30
active = true
IO.puts(name)
IO.puts(age)
IO.puts(active)

Atoms

Atoms are constants whose value is their own name. They start with a colon.

status = :ok
IO.puts(status)

Atoms like :ok, :error, and :not_found are used extensively in Elixir for tagging results.

Your Turn

Create variables:

  • name = "Alice"
  • age = 30
  • active = true
  • status = :ok

Print each one with IO.puts.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.