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.
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.
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.
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.
Just so you know, this is the same in JavaScript and according to JSLint should ALWAYS be used as a type-check, which technically makes == redundant. But I guess that's just personal preference
when we say "A is equal to B" this can mean several quite different things
etc
most languages do have different operators or functions for different kinds of equality , see http://en.wikipedia.org/wiki/Equality_%28relational_operator%29#Object_identity_vs._Content_equality