var t = a&&b;的问题

var a = "avalue";
var b = "bvalue";
var t = a&&b;
console.info(t); // bvalue

var a = "";
var b = 1;
var t = a&&b;
console.info(t); // ""

总结:

其他语言的结果为boolean值,js却不是这样,而是相当于

if(a){b}else{a}

而var t=a||b;相当于if(a){a}else{b}

如果感觉不错,请 一个!
by simpman
原文地址:https://www.cnblogs.com/simpman/p/3410191.html