The Inequality Operator is a highly common operator in programming languages. Most programming languages have the “not equal” operator as !=
.
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.
# != OperatorIO.puts "!= Operator"IO.puts "Same Value and Same Data Type:"IO.puts 1 != 1IO.puts "Same Value and Different Data Type:"IO.puts 1 != 1.0IO.puts "Different Value and Same Data Type:"IO.puts 1 != 2IO.puts "Different Value and Different Data Type:"IO.puts 1 != 2.0# !== OperatorIO.puts "!== Operator"IO.puts "Same Value and Same Data Type:"IO.puts 1 !== 1IO.puts "Same Value and Different Data Type:"IO.puts 1 !== 1.0IO.puts "Different Value and Same Data Type:"IO.puts 1 !== 2IO.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