What's this =! operator?

m0nhawk picture m0nhawk · Jan 9, 2014 · Viewed 47.5k times · Source

I was surprised by this code:

if (a =! b) { // let it be on false
    ...
}

But a is never assigned by a value. What's this operator about?

Answer

Mike Seymour picture Mike Seymour · Jan 9, 2014

That's two operators, = and !, not one. It might be an obfuscated way of writing

a = !b;
if (a) {
    // whatever
}

setting a to the logical inverse of b, and testing whether the result is true (or, equivalently, whether b was false).

Or it might be a mistyping of a != b.