== Why is this an issue?

Mixing up the order of operations will almost always yield unexpected results.


Similarly, mis-applied negation will also yield bad results. For instance consider the difference between ``++!key in dict++`` and ``++!(key in dict)++``. The first looks for a boolean value (``++!key++``) in ``++dict++``, and the other looks for a string and inverts the result. ``++!obj instanceof SomeClass++`` has the same problem.


This rule raises an issue when the left operand of an ``++in++`` or ``++instanceof++`` operator is negated.


=== Noncompliant code example

[source,javascript]
----
if (!"prop" in myObj) {  // Noncompliant;  "in" operator is checking property "false"
  doTheThing();  // this block will be never executed
}

if (!foo instanceof MyClass) {  // Noncompliant; "!foo" returns a boolean, which is not an instance of anything
  doTheOtherThing();  // this block is never executed
}
----


=== Compliant solution

[source,javascript]
----
if (!("prop" in myObj)) {
  doTheThing();
}

if (!(foo instanceof MyClass)) {
  doTheOtherThing();
}
----


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

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

=== Message

Add parentheses to disambiguate this expression.


=== Highlighting

minus operator


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