I would like to know the difference between == and === when making expressions and conditionals with elixir
I would like to know the difference between == and === when making expressions and conditionals with elixir
Unlike most languages, ===
does not double-check equivalence and type. As in javascript:
> 1 === "1"
false
> 1 == "1"
true
In Elixir, the difference between ==
and ===
is that the latter is more stringent when comparing integers and floats:
iex> 1 == 1.0
true
iex> 1 === 1.0
false
You can use ==
in all conditions that do not use numbers
since the difference between ===
and ==
affects comparison between numbers only.
I'll leave two sources here for a better understanding of the subject:
Documentation: link
Question on stackoverflow in English: link