==(Equality)
✔Used for comparing two variables and ignoring the data type of variable.
✔Returns true only if the two operands are equal and false for not equal.
===(Strict Equality)
✔Used for comparing two variables but also checks the data type and compares the two values.
✔Returns true only if both the values and data types are same.
🚀Both("==" and "===") are comparison operators.
Top comments (3)
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😅.
这....