字符串0.在php和js中转换为布尔类型 值是false还是true

在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 type="text/javascript">    

   var a='0';      

   if(a){       

     alert(1);      

  }else{             

    alert(0);       

  }

 </script>  值为true。

 

posted @ 2015-09-24 14:21  Grass_to  阅读(1736)  评论(0编辑  收藏  举报