Using Elixir 1.12.3.
New to this programing paradigm. When I specify “8” == 8 in iex it returns false. I indeed get the same result when I specify “8” === 8. According to the Elixir/Erlang definition the double == operator is supposed to type cast the string to an integer and return true. Any insights would be greatly appreciated.
The observed behavior is correct AFAIK
Where did you find that information? Maybe it mentions floats specifically?
=== behaviour differs ONLY for numerics (aka integers and floats). Otherwise it always is strict with a type and there is never any conversion between types.
According to the documentation:
The only difference between
=== is that
=== is strict when it comes to comparing integers and floats:
iex> 1 == 1.0
iex> 1 === 1.0
!== act as the negation of
Base Elixir will never perform any kind of implicit type coercion, so this is the only exception when it comes to comparisons.
There is another case though not related to
== which is falsyness and truthyness.
false are the only falsy values in Elixir, everything else is truthy. Meaning that in this snippet:
if val do
It will print Falsy! if
val is either
false, and for any other value it will print Truthy! But still
nil == false will return