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

后端 未结 5 848
旧时难觅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:03

    Another way could be using Number()

    Number(true) // = 1
    Number(false) // = 0
    

提交回复
热议问题