Fwd: Boolean equivalent to pre-increment and post-icnrement

# Bob Myers (21 days ago)

In the stupid idea of the day department, for some reason I have felt the urge more than once in recent months for an operator which would invert the value of a boolean variable while evaluating to its pre-inversion value. For example:

if (bool!!) console.log("used to be true");

The post-inversion case is less important since I can just write if (bool = !bool).

Bob

# Sebastian Malton (21 days ago)

An HTML attachment was scrubbed... URL: esdiscuss/attachments/20180829/03a5e025/attachment

# Steve Fink (20 days ago)

On 08/29/2018 12:13 PM, Bob Myers wrote:

In the stupid idea of the day department, for some reason I have felt the urge more than once in recent months for an operator which would invert the value of a boolean variable while evaluating to its pre-inversion value. For example:

if (bool!!) console.log("used to be true");

The post-inversion case is less important since I can just write if (bool = !bool).

There's always

if (counter++ & 1) console.log("used to be true");     if (++counter & 1) console.log("is now true");

or (counter++ % 2) if you prefer. And you get a free cycle counter in the bargain! (At the cost of flatlining to false at 2**53.)