
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
59 lines
1.3 KiB
Plaintext
59 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
``++null++`` and ``++undefined++`` are similar but not synonymous concepts in Javascript. Use a "hard" test (``++===++`` or ``++!==++``) for one, and you'll miss the other. Soft tests (``++==++``, and ``++!=++``) on the other hand, will pick up both non-values, as well as empty string.
|
|
|
|
|
|
Even if you mean to make the distinction in your code between ``++null++`` and ``++undefined++``, doing so is an extremely questionable practice that is likely to confuse both users and maintainers. Instead, use one or the other and test for both using soft tests.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
function func1(p1, p2) {
|
|
|
|
if (p1 === null) { // Noncompliant
|
|
return;
|
|
}
|
|
if (p1 === undefined) { // Noncompliant
|
|
return;
|
|
}
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
function func1(p1, p2) {
|
|
|
|
if (p1 == null) { // true for null, undefined
|
|
return;
|
|
}
|
|
// ...
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use the "xx" operator instead.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 13 Nov 2015, 14:58:00 Linda Martin wrote:
|
|
\[~elena.vilchik] I think this rule requires some digging, I let you do that.
|
|
|
|
endif::env-github,rspecator-view[]
|