The "==" operator is used
to check if two values
are equal.
It compares the values without
considering their data types.
Few examples:
On the other hand, the "==="
operator is primarily used in
case statements to perform
pattern matching.
It behaves differently based
on the class of the object
being compared.
Let's see a couple of examples:
In the first example, the "==="
operator is used with a range
object (1..5)
and checks if
the value 3 falls within that
range. Since it does, Boolean
true
is returned.
In the second example, the "==="
operator is used with a regular
expression /tar/
to match it
against the string "Guitar".
Since the string contains the
pattern defined by the regular
expression, it returns
Boolean true
.
In the third example, we are checking
if the value 4 is a part of Integers
.