Convert True->1 and False->0 in Javascript?

后端 未结 5 897
旧时难觅i
旧时难觅i 2020-12-22 23:22

Besides :

true ? 1 : 0

is there any short trick which can \"translate\" True->1 and False->0 in Javascript ?

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 00:08

    You can use ~~boolean, where boolean is (obviously) a boolean.

    ~~true  // 1
    ~~false // 0
    

提交回复
热议问题