Shorthand for flipping a boolean variable

前端 未结 5 1374
礼貌的吻别
礼貌的吻别 2021-02-01 03:13

How can I flip the value of a boolean variable in javascript, without having to include the variable name twice? So

foobarthings[foothing][barthing] = !foobarthi         


        
5条回答
  •  悲&欢浪女
    2021-02-01 03:48

    You can do this:

    foo ^= 1
    

    But this really switches foo between 0 and 1, not true and false.

提交回复
热议问题