I am using lint and for the following:
if (json.RowKey != json.NewRowKey)
It gives me a message:
Expected '!==' and instead saw '!='.
Can someone explain what this means?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
==will attempt to convert the types of the two operands to be the same before comparing them. Thus"2" == 2istrue.===will not attempt to convert the types of the two operands so if they are not the same type, they will never be===. Thus"2" === 2isfalse.It is better to use
===and!==as your default choice and only use==or!=when you explicitly want to allow type conversion. If you are not expecting the two operands to be different types, then===and!==is more likely to do what you are expecting.This avoids coding mistakes when things are not really equal and your code doesn’t intend for them to be equal.
Some odd things that happen with
==(and do not happen with===) that you may not expect and can lead to trouble. All of these evaluate totrue:There’s more detail written here: Which equals operator (== vs ===) should be used in JavaScript comparisons?