What is the difference between "===" and "==" in Elixir?

Asked

Viewed 116 times

2

I would like to know the difference between == and === when making expressions and conditions with elixir

1 answer

3


Different from 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 accurate when comparing whole numbers and floats:

iex> 1 == 1.0
true
iex> 1 === 1.0
false

You can use == under all conditions not used numbers bearing in mind that the difference between === and == affects comparison only between numbers.

I will leave two sources here for greater understanding of the subject:

Documentation: https://elixir-lang.org/getting-started/basic-operators.html
Question at stackoverflow in English: https://stackoverflow.com/questions/32347090/difference-between-double-equals-and-triple-equals-for-string-comparision-in-eli

Browser other questions tagged

You are not signed in. Login or sign up in order to post.