It's a bit more complex than that. The weak typed comparison == performs type coercion if necessary before the actual comparison. This means everything will be coerced into the type of the simplest value of both sides, e.g.
{}=='[object Object]'// true
The simplest type here is the string on the right, so the .toString() method is applied before the comparison. The order of complexity from top to bottom is object (includes arrays and other instances), function, string, number, boolean. null is actually an object and undefined contains no value at all and thus is coerced to false.
So the weak typed comparison has to do a lot more than the type-safe one and thus is slower.
Thanks for the comment, I really appreciate that.❤
My main focus was highlighting the basics of these operators so that for beginners it's easy to understand otherwise most of then would run away😅.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
It's a bit more complex than that. The weak typed comparison
==
performs type coercion if necessary before the actual comparison. This means everything will be coerced into the type of the simplest value of both sides, e.g.The simplest type here is the string on the right, so the
.toString()
method is applied before the comparison. The order of complexity from top to bottom is object (includes arrays and other instances), function, string, number, boolean.null
is actually an object andundefined
contains no value at all and thus is coerced tofalse
.So the weak typed comparison has to do a lot more than the type-safe one and thus is slower.
Thanks for the comment, I really appreciate that.❤
My main focus was highlighting the basics of these operators so that for beginners it's easy to understand otherwise most of then would run away😅.