The operator to be used depends on your needs.
"==" checks if two values ββare equal after they have been converted to the same data type (if possible). Thus, "5" == 5 will be true, since the string "5" is converted to a number, and then a check is made, and obviously 5 is really 5.
"===" checks if two values ββare the same AND types and equal. Thus, "5" === 5 will evaluate to false because one is a string and one is a number.
In terms of choice of use, it comes down to expectations. If you expect two values ββthat you are comparing with the same type, you should use "===". However, if they can be of different types and you want the comparison to perform automatic conversion (for example, comparing line 5 with number 5), you can use "==".
In the case of your examples, everything should be fine with the "==" operator, but for security of the added type, you can certainly use the "===" operator. For example, I usually check for zeros.
Hope this helps.
source share