时间: 2020-11-23|58次围观|0 条评论

在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。

 

转载于:https://www.cnblogs.com/wqy61/p/4835221.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/99218400

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《字符串0.在php和js中转换为布尔类型 值是false还是true
   

还没有人抢沙发呢~