JetBrains Rider 2017.2 Help

Code Inspection: Using of coerced equality

In JavaScript and TypeScript code, JetBrains Rider suggests replacing the equality operator == with a stricter identity operator ===. Using === is a good practice because == may work unpredictably — the reason is that the == operator performs type coercing (conversion) before comparison, which may lead to unexpected results of comparison. The identity operator ===, which works only with operands of identical type, prevents such errors. You can learn more about these operators in the answers to this StackOverflow question.

In the example, JetBrains Rider recommends using the identity operator:

Suboptimal codeAfter the quick-fix
function TestDisplay(id) { if (document.getElementById(id).style.display == "") { document.getElementById(id).style.display = "none"; } //... }
function TestDisplay(id) { if (document.getElementById(id).style.display === "") { document.getElementById(id).style.display = "none"; } //... }
Last modified: 17 November 2017

See Also