Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can === hold when == doesn't?

Are there any cases where

x == y //false
x === y //true

is that ever possible in JS? :)

like image 258
Alexander Mills Avatar asked May 22 '15 19:05

Alexander Mills


People also ask

Can I compare strings with ==?

You should not use == (equality operator) to compare these strings because they compare the reference of the string, i.e. whether they are the same object or not. On the other hand, equals() method compares whether the value of the strings is equal, and not the object itself.

Why do we prefer === and !== Over == and != In JavaScript?

The == and === operators are used to check the equality of two operands. The != and !== operators are used to check the inequality of two operands.

Which of the following is true about == and === operators?

= is called as assignment operator, == is called as comparison operator whereas It is also called as comparison operator. = does not return true or false, == Return true only if the two operands are equal while === returns true only if both values and data types are the same for the two variables.

Why does JavaScript use === instead of ==?

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 ...


1 Answers

No. That's never possible. === checks for type and equality. == just checks for equality. If something isn't == it can never be ===.

like image 175
Justin Niessner Avatar answered Oct 19 '22 00:10

Justin Niessner