What is "not equal" in Elixir?

Inequality Operator

The Inequality Operator is a highly common operator in programming languages. Most programming languages have the “not equal” operator as !=.

Inequality in Elixir

Elixir has two options for inequality checks, != and !===. The != operator is not as strict as the latter, and it only compares the values, not the types. This means that != returns true if the compared values are different, and false if they are the same. It does not consider the data types.

In contrast, the !== operator compares both the values and data types. This means that the !== operator returns true if the compared values are different and have different data types, if only the values are different, or if only the data types are different. It returns false only if both ​values and data types are the same.

# != Operator
IO.puts "!= Operator"
IO.puts "Same Value and Same Data Type:"
IO.puts 1 != 1
IO.puts "Same Value and Different Data Type:"
IO.puts 1 != 1.0
IO.puts "Different Value and Same Data Type:"
IO.puts 1 != 2
IO.puts "Different Value and Different Data Type:"
IO.puts 1 != 2.0
# !== Operator
IO.puts "!== Operator"
IO.puts "Same Value and Same Data Type:"
IO.puts 1 !== 1
IO.puts "Same Value and Different Data Type:"
IO.puts 1 !== 1.0
IO.puts "Different Value and Same Data Type:"
IO.puts 1 !== 2
IO.puts "Different Value and Different Data Type:"
IO.puts 1 !== 2.0

This program compares integers with integers and floats that have similar and differing numeric values by using both operators.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved