Elixir basics · Lesson 10 (open contents)
01 · Let the code speak02 · Meet six kinds of values03 · Put values together04 · Build a new list05 · Make the shapes match06 · Choose with case07 · Parse a number safely08 · Unpack &1 and the pipe09 · Put code in a project10 · Ask precise true-or-false questions11 · Read and update nested data12 · Count visible text and bytes13 · Let function clauses choose14 · Solve a list twice15 · Choose the smallest clear control form16 · Give domain data a shape17 · Put one tested module in Mix18 · Make success and failure predictable19 · Read and write one real file20 · Take only the data you need21 · Give different data one shared action22 · Write a callback contract23 · Write down the data contract24 · Test behavior and boundaries25 · Turn a project into a command26 · Write the project promise27 · Parse one real line28 · Keep the public API small29 · Make the promise executable30 · Package the edge and leave clues31 · Prove the project is done
ELIXIR · FOUNDATION · LESSON 1025 minutes

Ask precise true-or-false questions

Compare values and separate truthy operators from strict Boolean operators.

01 · Start with the whole example

Run this first

Run it once, change one input, and compare the new result.

Elixir
# Compare equality and truthiness
value = 0
{value == 0.0, value === 0.0, value || :fallback, false or true}
Check the result first
  • The tuple is {true, false, 0, true}; zero is truthy in Elixir.
02 · Take the code apart

Read from the first line down

  1. Read == / ===: Compare loosely or strictly.
  2. Read ||: Return the left value when it is truthy; otherwise return the right value.
  3. Read or: Combine Boolean values only.
03 · Meet the new symbols

Symbols are not secret signs

== / ===

Compare loosely or strictly.

||

Return the left value when it is truthy; otherwise return the right value.

or

Combine Boolean values only.

04 · Ideas inside the code

Match each name to its meaning

01

truthy

Only false and nil are falsy in Elixir; every other value is truthy.

02

strict equality

=== compares both value and numeric type, while == allows integer-float equality.

03

Boolean operators

and, or, and not require Boolean inputs; &&, ||, and ! accept any value.

05 · Make the idea clear

Why these forms are useful

Run the example first. Predict one result, then change one input and run it again.

Only false and nil are falsy in Elixir; every other value is truthy.

=== compares both value and numeric type, while == allows integer-float equality.

06 · Change it yourself

Close the answer and try

Compare 2 with 2.0 twice, then give nil a fallback value.

Practice starting point
{2 ____ 2.0, 2 ____ 2.0, nil ____ :missing}

Target result: Return {true, false, :missing}.

Stuck? Read one hint

Use ==, ===, and || in that order.

After you run it, see one answer
One answer
{2 == 2.0, 2 === 2.0, nil || :missing}
Think about it: Is `0` falsy in Elixir?

No. Only false and nil are falsy.

Take with you

Remember these three lines

  1. 1

    Use === when numeric type matters.

  2. 2

    Zero and empty collections are truthy.

  3. 3

    Use strict Boolean operators only with Booleans.

Lesson completeRun the code once, then mark this lesson as done.