关于JavaScript的一道初级面试题

版权声明:转载请注明出处 http://blog.csdn.net/yezhongdefeng https://blog.csdn.net/YeZhongDeFeng/article/details/78447546

参考-前端面试江湖(李红米)

这两天看到一道题很有意思,分享一下:

false==0的结果是多少?

解析:因为逻辑值真(True)和假(False)被当作数值运算时,其值分别为1和0。

所以Max(0,-1,True)结果为1,MIN(False,1,2)结果为0。

故false==0结果为false。

PS:不太理解上边解释的内容,自己写了一段JS代码,发现结果为True。

<html>
<script type="text/javascript">
if(false==0)
{
  document.write("结果为True");
}
else
{
  document.write("结果为False");
}
</script>
</html>
上述代码运行后,在网页上显示的结果为True,不知道这道题是哪里出了问题。

猜你喜欢

转载自blog.csdn.net/YeZhongDeFeng/article/details/78447546