I've used C++ and Java before and they don't have this ===
operator.
How come they manage without it but in languages like PHP its key.
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
Use === if you want to compare couple of things in JavaScript, it's called strict equality, it means this will return true if only both type and value are the same, so there wouldn't be any unwanted type correction for you, if you using == , you basically don't care about the type and in many cases you could face ...
The === operator means "is exactly equal to," matching by both value and data type. The == operator means "is equal to," matching by value only.
=== (Triple equals) is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar type. This operator performs type casting for equality. If we compare 2 with “2” using ===, then it will return a false value.
Actually equals
in Java and ==
in C# act like ===
does in php. I.e. "24".equals(24)
will return false.
What java and C# don't have an equivalent of is PHP's ==
(i.e. an operator/method such that "24".fuzzyEquals( 24 )
would return true). And that's because C# and Java are strongly typed and such an operator would be against their philosophy.
Because PHP is not type safe. == compares 2 values, but === compares the values AND checks if their class types are the same.
I believe "2" == 2 returns true, while "2" === 2 returns false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With