JavaScript if 判断null undefined 避免踩坑

xiaoxiao2021-02-28  23

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;
转载请注明原文地址: https://www.6miu.com/read-2628889.html

最新回复(0)