nodeJs 对比 (!value) 和 _.isEmpty(value) 区别

对比 (!value) 和 _.isEmpty(value) 区别

不废话,上代码

const _ = require("lodash");

let check = [];
let datas = [
  null,
  undefined,
  {},
  { a: "" },
  { undefined },
  [],
  [[]],
  [[[]]],
  [{}],
  -1,
  0,
  1,
  "",
  "-1",
  "0",
  "1",
  true,
  false,
  "string",
  "123456",
  "null",
  "undefined",
];

for (const item of datas) {
  check.push({
    value: item,
    "(!value)": !item,
    "_.isEmpty(value)": _.isEmpty(item),
  });
}
console.table(check);

结果

(index) value (!value) _.isEmpty(value)
0 null true true
1 undefined true true
2 {} false true
3 { a: ‘’ } false false
4 { undefined: undefined } false false
5 [] false true
6 [ [] ] false false
7 [ [Array] ] false false
8 undefined true true
9 [ {} ] false false
10 -1 false true
11 0 true true
12 1 false true
13 ‘’ true true
14 ‘-1’ false false
15 ‘0’ false false
16 ‘1’ false false
17 true false true
18 false true true
19 ‘string’ false false
20 ‘123456’ false false
21 ‘null’ false false
22 ‘undefined’ false false

你可能感兴趣的:(技巧,node.js)