在各种框架中经常看到一些简便的或且表达式取值,比如:
var a = xx && obj.xx && win.xxx;
var b = xx || obj.xx || win.xxx;
这是什么意思呢,用过的人都知道,对于javascript而言,不一定是boolean才可以判断的,所有对象都可以判断,包括undefined,null等
以下是对JS6种类型的判
| 类型 | 条件判断为 | 
|---|---|
| Function | True | 
| Undefined | False | 
| String | 空字符串为false,否则为true | 
| number | 0为false,其它为true | 
| boolean | true/false | 
| object | null为flase,不为空为true | 
这样就可以看到这个意思了
比如: