Consider using a "Value and Type" comparison in if statements |
Consider using a "Value and Type" comparison in if statements, it is possible for values to be the same but types to be different. This helps to prevent cases such as "0 == false" from occuring. This isn't required were a type is asserted
CheckId | SPC058901 |
---|---|
TypeName | ConsiderToUseStrongComparisonInIfStatements |
Severity | Warning |
Type | JavaScriptFile |
Bad Practice
// Ensure the objects are of same value, then return desired value
if(object1 == false) return true;
if(object2 != 1) return true;
if(object1 == false) return true;
if(object2 != 1) return true;
Good Practice
// Ensure the objects are of same type and value, then return desired value
if(object1 === false) return true;
if(object2 !== 1) return true;
if(object1 === false) return true;
if(object2 !== 1) return true;
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.