How to toggle a boolean?

后端 未结 6 1256
醉话见心
醉话见心 2020-12-07 07:14

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:<

6条回答
  •  情书的邮戳
    2020-12-07 07:45

    bool === tool ? bool : tool
    

    if you want the value to hold true if tool (another boolean) has the same value

提交回复
热议问题