== Why is this an issue?

The result of an expression with an arithmetic operator ``/, *, %, {plus}{plus}, --, -, {plus}=, -=, *=, /=, %=, {plus}`` or unary operator ``+++, -++`` when at least one operand is ``++Object++`` or ``++Undefined++`` will be always a ``++NaN++`` (Not a Number).


=== Noncompliant code example

[source,javascript]
----
x = [1, 2];
var y = x / 4;  //Noncompliant
----


=== Exceptions

* ``++Date++`` operands: they are implicitly converted to numbers.
* The binary ``+`` operator with ``++Object++`` operand (concatenation).


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Change the expression which uses this operand so that it can't evaluate to "NaN" (Not a Number).


=== Highlighting

Primary: operand triggering the rule

Secondary: operator

Secondary: second operand


'''
== Comments And Links
(visible only on this page)

=== on 18 Oct 2016, 10:47:28 Pierre-Yves Nicolas wrote:
We may raise false positives when one of the operands is an ``++Object++``. An ``++Object++`` which wraps some kind of number may have a valid ``++valueOf++`` method: see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf#Examples[an example].

If we see that we raise too many false positives, we can:

* raise an issue only on some kinds of ``++Object++`` for which we know that there is a problem: ``++Array++``, ``++Date++``, ``++Function++``, ``++Regexp++``
* keep the same exception on ``+`` for these kinds of operand

=== on 25 Oct 2016, 15:44:36 Pierre-Yves Nicolas wrote:
\[~jeanchristophe.collet] I think that the message should always be "imperative", e.g. "Remove...", "Change...".

=== on 25 Oct 2016, 15:47:45 Pierre-Yves Nicolas wrote:
\[~jeanchristophe.collet] What about ``+++=++``?

=== on 25 Oct 2016, 16:01:10 Jean-Christophe Collet wrote:
I addressed both comments above.

=== on 31 Oct 2016, 12:24:53 Pierre-Yves Nicolas wrote:
More detailed message: "The value of this operand is (undefined|an object) on at least one path of execution. Refactor the code to avoid having NaN ("Not a Number") as the result of the parent expression."

endif::env-github,rspecator-view[]
