首页 > > > javascript中 &&运算符
ES中所述:
如果某个运算数不是原始的 Boolean 型值,逻辑 AND 运算并不一定返回 Boolean 值:
如果一个运算数是对象,另一个是 Boolean 值,返回该对象。
代码:
var a = {
name: 'a'
};
console.log(true && a); //- Object {name: "a"}
console.log(a && true); //- true
有人可以帮解释下为什么第二个不是输出a吗
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/818/viewspace-3148047/ ,如需转载,请注明出处,否则将追究法律责任。