iex(1)> 5 == 5.0
In the above code, the
== operator checks if both sides of the value are same and it does not care about the data types. According to the Elixir guide, Atoms are constants whose name is their value. If it checks only the value, why does the below code return false?
iex(1)> :hello == "hello"
Hello and welcome,
You mght find how operators works here
You have strict equality with === between numbers, but atoms will never be strings
Notably strict equality
=== only matters when you are comparing integers and floats. In all other comparisons in Elixir, the comparison will be false if the data types are different.
:hello is an atom and internally represented as an integer. This is handled by the runtime. The exact value of the integer is not known at compile time. They are generated at runtime and stored in an atom table. Atoms are similar to static consts or enums in other languages. “hello” on the other side is a string.