How the statement if is evaluated in javascript
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
Is there a standard function to check for null, undefined, or blank variables in JavaScript?
在javascript中,
作为一个结果,无论是在条件下的表达,它是通过转换为布尔
Let exprRef be the result of evaluatingExpression .If ToBoolean(GetValue(exprRef)) istrue , then
Return the result of evaluating the firstStatement .Else,
Return the result of evaluating the secondStatement .
OR值为每个数据类型转换规则,对布尔是明确定义的。操作系统,例如,在两个
如果你的"falsey测试值的条件",是虚假的。例如:
1 2 3 4 5 6 7 8 | var a = 0; if (a) { // Doesn't happen } else { // Does happen } |
如果你测试"还是"真值的条件:
1 2 3 4 5 6 7 8 | var a = 1; if (a) { // Does happen } else { // Doesn't happen } |