I have a variable that stores false or true , but I need 0 or 1 instead, respectively.(我有一个存储false或true的变量,但我分别需要0或1 。)
false
true
0
1
Use the unary + operator , which converts its operand into a number.(使用一元+运算符 ,它将其操作数转换为数字。)
+
+ true; // 1 + false; // 0
1.4m articles
1.4m replys
5 comments
57.0k users