Nil is an English word meaning "nothing" or "zero". In Elixir, nil is a special value that means an absence of a value.
# I do not have a favorite color
favorite_color = nil
nil is an atom, but it is usually written as nil, not :nil. The boolean values true and false are atoms too.
nil === :nil
# => true
true === :true
# => true
You can check if a variable's value is nil using ==, with pattern matching, or using the is_nil guard.
def call(phone_number) do
if phone_number == nil do
:error
end
end
def call(phone_number) when is_nil(phone_number) do
:error
end
def call(nil) do
:error
end