Is there a way to convert NaN values to 0 without an if statement:(没有if语句,有没有办法将NaN值转换为0:)
if (isNaN(a)) a = 0;
You can do this:(你可以这样做:)
a = a || 0
0
false
null
undefined
""
NaN
a = a ? a : 0;
a = +a || 0
a
'123'
+['123'] // 123
2.1m questions
2.1m answers
60 comments
57.0k users