2021-04-28 16:49:39 +02:00
The use of comparison operators (``++<++``, ``++<=++``, ``++>=++``, ``++>++``) with strings is not likely to yield the expected results. Make sure the intention was to compare strings and not numbers.
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
var appleNumber = "123";
var orangeNumber = "45";
if (appleNumber < orangeNumber) { // Noncompliant, this condition is true
alert("There are more oranges");
}
----
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
var appleNumber = "123";
var orangeNumber = "45";
if (Number(appleNumber) < Number(orangeNumber)) {
alert("There are more oranges");
}
----
2021-04-28 18:08:03 +02:00
2021-04-28 16:49:39 +02:00
== Exceptions
The rule ignores string comparisons occurring in the callback of a sort invocation, e.g.:
----
const fruits = ['orange', 'apple', 'banana'];
fruits.sort((a, b) => a < b);
----
2021-04-28 18:08:03 +02:00
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]