Shorthand for flipping a boolean variable

前端 未结 5 1373
礼貌的吻别
礼貌的吻别 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:54

    var value = true;
    alert(value);
    value ^= true;
    alert(value);​
    

    You could get 1 or 0 here

提交回复
热议问题