Boolean(something) 会把里面的变量转化为布尔型
当我们用if(something)判断的时候,相当于调用了这个函数
转化规则如下
DATA TYPE |
VALUES CONVERTED TO TRUE |
VALUES CONVERTED TO FALSE |
Boolean |
true |
false |
String |
Any nonempty string |
“” (empty string) |
Number |
Any nonzero number (including infinity) |
0, NaN (See the “NaN” section later in this chapter.) |
Object |
Any object |
null |
Undefined |
n/a |
undefined |
时间: 2024-10-03 15:32:31