65 lines
1.3 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
In a Zen-like manner, ``++NaN++`` isn't equal to anything, even itself. So comparisons (``++>, <, >=, <=++``) where one operand is ``++NaN++`` or evaluates to ``++NaN++`` always return ``++false++``. Specifically, ``++undefined++`` and objects that cannot be converted to numbers evaluate to ``++NaN++`` when used in numerical comparisons.
This rule raises an issue when there is at least one path through the code where one of the operands to a comparison is ``++NaN++``, ``++undefined++`` or an ``++Object++`` which cannot be converted to a number.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
var x; // x is currently "undefined"
if (someCondition()) {
x = 42;
}
if (42 > x) { // Noncompliant; "x" might still be "undefined"
doSomething();
}
var obj = {prop: 42};
if (obj > 24) { // Noncompliant
doSomething();
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
var x;
if (someCondition()) {
x = 42;
} else {
x = foo();
}
if (42 > x) {
doSomething();
}
var obj = {prop: 42};
if (obj.prop > 24) {
doSomething();
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]