Using JavaScript-bitwise AND and -bitwise NOT for setting a number to 0
Well, yes, num &amp; (~num) does result in zero. Not much to review there. Seems you've solved the task you were given.

Of course, one might as well return/assign a literal zero, and skip two bitwise operations.

There's one JavaScript-specific caveat to all of this though: JavaScript's bitwise operations only work on 32-bit integers. However, that's not a datatype that usually exists in JavaScript: Numbers in JavaScript are all IEEE 756 64-bit floats. 

The moment you use a bitwise operator on them, however, they are converted (with potential loss) to 32-bit ints, and the result then represented as a float again.

Of course, that's all academic, since whatever int representation you get, a &amp; (~a) will result in zero.

But other bitwise operations can give strange results. For instance, OR'ing with zero should just return the number unaltered, but if the number's too large, its most-significant bit will end up being interpreted as the sign bit as the internal 32-bit conversion is always signed. So you get things like this:

2147483647 | 0 // =&gt; 2147483647
2147483648 | 0 // =&gt; -2147483648


The second number is large enough to flip the high bit, and thus it's interpreted as negative.

Anyway, point is: Yes, a &amp; (~a) will result in zero, for any value of a, despite JS's internal strangeness, because whatever it converts the input to, it also negates. But it's a special case; in other contexts bitwise operations in JS may be treacherous.