在php 中 $a = '0'; $b = (bool)$a; var_dump($a);//输出false 在js中官方说明: Note:If the value parameter is omitted, or is 0, -0, null, , false, undefined, or NaN, the object is set to false. Otherwise it is set to true (even with the string false)! 测试: <script
值为flase的有: false 0 "" //空串 null undefined NaN 除了以上的之外的都是ture,包括"0" (zero in quotes), "false" (false in quotes) , empty functions, [](空数组), and {}(empty objects),都是为true var a = !!(0); // false var b = !!("0"); // tr