背景在检验时,当值为null,和undefined,0,其boolean值都是false,但是我们需要0时校验为true.
Created
December 31, 2019 02:46
-
-
Save upangka/78138734e61bad1046955b72bc0730cd to your computer and use it in GitHub Desktop.
javascript check for null ,undefined but not include 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let foo = 0 | |
// check null,undefined not include 0 | |
const f = (arg)=>{ return !arg && arg !== 0} | |
console.log(f(foo)) // false | |
foo = void 0 // undefined | |
console.log(f(foo)) // true | |
foo = null | |
console.log(f(foo)) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment