Use a +
with two numbers and you'll get addition. But use it with a string and anything else, and you'll get concatenation. This could
be confusing, specially if it's not obvious that one of the operands is a string. It is recommended to explicitly convert the non-string component to
make it easier to understand to future maintainers.
This rule raises an issue when +
is used with a string and a non-string.
var x = 5 + 8; // okay var z = "8" var y = 5 + z; // Noncompliant; yields string "58"
var x = 5 + 8; var z = "8"; var y = 5 + Number(z);