42 lines
1019 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
``++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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
function func1(p1, p2) {
if (p1 === null) { // Noncompliant
return;
}
if (p1 === undefined) { // Noncompliant
return;
}
// ...
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
function func1(p1, p2) {
if (p1 == null) { // true for null, undefined
return;
}
// ...
}
----
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::rspecator-view[]