sea-stream

 

//    var a = "";
//    var a = " ";
//    var a = null;
//    var a = undefined;
//    var a = [];
//    var a = {};
//    var a = NaN;
    
    if(a === undefined) { // 只能用 === 运算来测试某个值是否是未定义的
        console.log("为undefined");
    }
    if(a == null) { // 等同于 a === undefined || a === null
        console.log("为null");
    }
    // String    
    if(a == "" || a == null || a == undefined){ // "",null,undefined
        console.log("为空");
    }
    if(!a){ // "",null,undefined,NaN
        console.log("为空"); 
    }
    if(!$.trim(a)){ // "",null,undefined
        console.log("为空");
    }
    // Array
    if(a.length == 0){ // "",[]
        console.log("为空");
    }
    if(!a.length){ // "",[]
        console.log("为空");
    }
    // Object {}
    if($.isEmptyObject(a)){ // 普通对象使用 for...in 判断,有 key 即为 false
        console.log("为空");
    }

 

分类:

技术点:

相关文章:

  • 2021-06-11
  • 2021-09-23
  • 2021-06-08
  • 2021-08-08
  • 2021-11-27
  • 2022-02-10
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2021-08-18
  • 2022-02-09
  • 2021-12-04
  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
相关资源
相似解决方案