2020-06-30 17:16:12 +02:00

33 lines
569 B
Plaintext

Comparing dissimilar types using the strict equality operators <code>===</code> and <code>!==</code> will always return the same value, respectively <code>false</code> and <code>true</code>, because no type conversion is done before the comparison. Thus, such comparisons can only be bugs.
== Noncompliant Code Example
----
var a = 8;
var b = "8";
if (a === b) { // Noncompliant; always false
// ...
}
----
== Compliant Solution
----
var a = 8;
var b = "8";
if (a == b) {
// ...
}
----
or
----
var a = 8;
var b = "8";
if (a === Number(b)) {
// ...
}
----