Hello Guys,
In this blog we are going to learn about "===" and "==" different with details understanding and examples.
JavaScript operators that you might have stumbled upon as a developer include "===", "==".
JavaScript's "==" operator is commonly utilized for loose comparison purposes.
It functions by converting both of the values to a common type and then comparing them for equality.
Here's an example:
The comparison operator "==" transforms the value of "17" from a string to a number before determining if the values match.
Consequently, if both versions of the data share the same properties and values, the comparison is marked as valid and returns true.
The results of the "==" operator can occasionally be surprising, including:
For strict comparison, the "===" operator is utilized.
This operator assesses equality between two values without altering their types.
Here's an illustration:
Returns false, since they are not the same type, the "===" operator compares the number "17" to the string "17" in this example.
In order to avoid pesky bugs, employing the "===" operator is wise, as this guarantees that you're comparing values of identical type.
It's best to make the "===" operator your go-to unless you have an explicit need to use lenient comparison.
Comments
Post a Comment