Will ==
and ===
work correctly in all browsers for DOM elements? If the code gets a reference to a raw DOM element in two different ways, will they be both ==
and ===
equal in all browsers?
The equality operator ( == ) checks whether its two operands are equal, returning a Boolean result. Unlike the strict equality operator, it attempts to convert and compare operands that are of different types.
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.
inequality operator returns false if two values are equal to each other according to == and returns true otherwise. The !==
Will == and === work correctly in all browsers for DOM elements?
Yes, those equality operators will work as defined by the ECMAScript standard.
One word of caution, ==
often does things that developers do not expect, such as casting to a string when compared to a string value. This would make the following statement true, although it might not be the desired result:
document.createElement('div') == '[object HTMLDivElement]'
In most cases, you'll want to use the ===
operator.
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