const a = null, b = undefined, c = 0;
console.log(a, b);
if (a) console.log('a');
if (b) console.log('b');
if (b == null) console.log('c');
out
null undefined
c
null === null # => true
undefined === undefined # => true
undefined === null # => false
undefined == null # => true
在if中,""
, and 0
, and NaN
, false
,null
,undefined
都为false
所以想报表中传数据时,经常遇到传来的数据不规范,需要补零
const a= !y ? 0 : y;