在javascript里
var bl=1&&3;
alert(bl);
弹出的是3
为什么阿,它返回的不是个boolean型么?
var bl=1&&3;
alert(bl);
弹出的是3
为什么阿,它返回的不是个boolean型么?
解决方案 »
- $java异步获取数据问题.
- 求高手解答,已经研究一天多了,都没有找到错误
- function $(id)是什么意思
- google chrome 下的SVG问题
- 两个事件 我不认识
- 一个IE下的BUG,高手来看
- javscript你们遇到过下面的问题没有?高手来解释下?
- 如何实现iframe的自适应高度 解决给分, 有经验者看看!1
- 高手们。。。。我这个map怎么不起作用,,
- 为什么document.all["test_" + i].cells[0].innerHTML 老是提示documentall[...].cells不是对象?
- 请问我这段非常简单的JavaScript代码运行时为什么浏览器左下角是黄色的“网页有错误”??
- 请教下 Javascript 代码这样放置可以吗?
This is the logical AND operator, which returns a Boolean true if both the operands are true. Logically it follows that if the first operand is false, then the whole expression is false, and this is how the operator works; It first evaluates the left hand operand, and if this returns false then, without going any further, it returns false for the whole expression. Otherwise it returns the value of the second operand: true or false for a Boolean value, or the actual value itself if non-Boolean. Assuming 'a' to be 3, 'b' to be 5, and 'c' to be 3, the following examples all return true:
var bl=!!(1&&3);
alert(bl);
</script>
&&
如果&&运算符左边的值可以转换成false (这些-- null,0,undefined,""--之一),那么&&就返回左边表达式的值,否则将继续计算第二个运算数,并且返回这个表达式的值
||
与&&雷同,只要||左边的值可以转换成true,就直接返回左边表达式的值,否则将继续计算第二个运算数,并且返回这个表达式的值你得这个1&&3=3,1||3=1也就好解释了
1&&3中, 1可以转换成true,于是继续计算右边的3,3也可以转换成true,最后就返回3(表达式的值)了
1||3中,1为true,不用继续计算,直接返回1(也是表达式的值)