JavaScript check if value is only undefined, null or false

后端 未结 9 2038
暗喜
暗喜 2021-01-31 08:09

Other than creating a function, is there a shorter way to check if a value is undefined,null or false only in JavaScript?

相关标签:
9条回答
  • 2021-01-31 08:34

    Try like Below

    var Boolify = require('node-boolify').Boolify;
    if (!Boolify(val)) {
        //your instruction
    }
    

    Refer node-boolify

    0 讨论(0)
  • 2021-01-31 08:39

    Well, you can always "give up" :)

    function b(val){
        return (val==null || val===false);
    }
    
    0 讨论(0)
  • 2021-01-31 08:41

    only shortcut for something like this that I know of is

    var val;
    (val==null || val===false) ? false: true;
    
    0 讨论(0)
提交回复
热议问题