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:
JavaScript
x
2
1
bool = bool ? false : true;
2
Advertisement
Answer
JavaScript
1
2
1
bool = !bool;
2
This holds true in most languages.