Question about double negation operator in JavaScript

I am studying the book JavaScript: Novice to Ninja and was wondering in what situation would you actually use the double negation operator !!?

I’ve not seen the book, but does it look something like this?

i--;

Actually, this is probably what you’re referring to - https://www.sitepoint.com/javascript-double-negation-trick-trouble/

It casts a variable to boolean.

Or, if you are working with numbers, it is a fast way (bitwise) to test if an integer is odd.

The double negation trick is not normally used, and is often reserved for code golf competitions.

Instead of using double negation, it’s more common to go without it, or to explicitly use Boolean() instead.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.