它被转换为布尔值。任何非空字符串的计算结果为真。
来自ECMAScript 语言规范:
12.5if声明
语义
生产IfStatement : if ( Expression  ) Statement  else Statement评估如下:
- 让exprRef是计算Expression的结果。
 
- 如果 ToBoolean(GetValue( exprRef )) 为true,则 
  
 
- 别的, 
  
 
9.2 ToBoolean
抽象操作 ToBoolean 根据表 11 将其参数转换为 Boolean 类型的值:
表 11 - ToBoolean 转换
未定义:false
  空:false
  布尔值:结果等于输入参数(无转换)。
  Number:如果参数为+0、-0或NaN,则结果为假;否则结果为真。
  字符串:如果参数为空字符串(其长度为零),则结果为假;否则结果为真。
  对象:真实
就==运算符而言,它很复杂,但其要点是,如果将数字与非数字进行比较,则后者将转换为数字。如果将布尔值与非布尔值进行比较,则布尔值首先转换为数字,然后适用上一句。
有关详细信息,请参阅第 11.9.3 节。
// Call this x == y.
if ("string" == true) 
// Rule 6: If Type(y) is Boolean,
//         return the result of the comparison x == ToNumber(y).
if ("string" == Number(true))
// Rule 5: If Type(x) is String and Type(y) is Number,
//         return the result of the comparison ToNumber(x) == y.  
if (Number("string") == Number(true))
// The above is equivalent to:
if (NaN == 1)
// And NaN compared to *anything* is false, so the end result is:
if (false)