javascriptoperatorsboolean-operations

Change a value from 0->1 or 1->0 with only mathematic operations


I have a variable on javascrit, initialized at 0. What I'd like to do is this :

and I'll avoid conditional statement (like if/else) to check what the value is.

I think I just do it with some matematic operation; I thought to a NOT operation, but I don't know how to do that operation without


Solution

  • x = 1-x;