The “==” in comparison operator is very familiar to programmers. In Javascript appear more “===”. So how are they similar and different? In this article, I will share with you all!
“==” operator
The “==” operator is used to check if the value of two elements is equal, but it only compares the value, not the data type Example:
In some other special cases when using “==”: + 0 has a numeric data type, but when compared with a boolean, it will be forced to a boolean with a value of false:
+ 1 has a numeric data type, but when compared with a boolean, it will be forced to a boolean with the value true:
+ “” has a data type of string, but when compared with a boolean, it will be forced to a boolean with the value false:
Operator “===”
The operator “===” also has the same thing as “==” that is also comparing in terms of values, but the difference is that “===” compares also on data types Example:
But
because 10 has a data type of number, and “10” has a data type of string
Conclude
So through the above article, I have shared about the similarities and differences between “==” and “===”. In case the operator is only interested in the value side, we use “==”, and when there are stricter conditions on the data type, we use “===”. In each practical problem we will encounter many cases, use “==” or “===” in the most effective way to match the requirements. Thank you for reading this article of mine, if you find it interesting, please help me 1 upvote.