函数判断与Js中的’&& ||‘+假值
_.isFunction = function(obj){
return typeof obj == 'function' || false;
}'' || [1,2] //[1,2]
'' && [1,2] //""
[1] || [] //[1]
[1] && [] //[]Last updated
_.isFunction = function(obj){
return typeof obj == 'function' || false;
}'' || [1,2] //[1,2]
'' && [1,2] //""
[1] || [] //[1]
[1] && [] //[]Last updated
let a = 'false';
let b = '0';
let c = "''";
let d = Boolean(a && b && c );
d; // truelet a = [];
let b = {};
let c = function(){};
let d = Boolean(a && b && c );
d; // truefunction foo(a,b){
a = a || 'hello';
b = b || 'world';
console.log(a + ' ' + b);
};
foo(1);// '1 world'function foo(){
console.log(a);
};
let a = 1;
a && foo();
//当第一个操作数为真值时,&&才会选择第二个操作数作为返回值,即前面的表达式为后面的表达式'把关'