Skip to content
Advertisement

How to toggle a boolean?

Is there a really easy way to toggle a boolean value in javascript?

So far, the best I’ve got outside of writing a custom function is the ternary:

bool = bool ? false : true;

Advertisement

Answer

bool = !bool;

This holds true in most languages.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement