是否所有非空字符串评估为true?字符串到布尔转换行为
Table 11 - ToBoolean Conversions Undefined: false Null: false Boolean: The result equals the input argument (no conversion). Number: The result is false if the argument is +0, -0, or NaN; otherwise the result is true. String: The result is false if the argument is the empty String (its length is zero); otherwise the result is true. Object: true
答案应该是肯定的。但后来我不知道为什么:
alert(" " == false);
回报真正。 {与"\t\n\r"
}相同的结果}
我没有任何特别的用例,我只是想知道它。
见我的答案在这里:http://stackoverflow.com/questions/10376179/n-t-r-0-is-true/10377034。 'false'被转换为'0'。 –
@FelixKling thx,我搜索了,找不到它。 –
好吧,我投票结束因为重复的问题...;)会接受第一个答案。 Thx给大家。 –