rspec/rules/S3003/rule.adoc

25 lines
578 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01: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.
2020-06-30 12:48: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");
}
----
== Compliant Solution
----
var appleNumber = "123";
var orangeNumber = "45";
if (Number(appleNumber) < Number(orangeNumber)) {
alert("There are more oranges");
}
----