• null,undefined,‘’,“”,“ ”,isNaN


    1.null,特指对象的值未设置,常用在释放对象,比如拖拽事件,拖拽后需要把 mousedown mousemove mouseup释放,也就是设置为null,其类型检测如下:

    var bonly=null;
    console.log(bonly);  // null
    console.log(typeof bonly);  // object
    var bonly={};
    console.log(bonly);  // 只有__proto__属性,指向Object
    console.log(typeof bonly);  // object
    

    2.undefined,表示的是未定义,以下3种情况会出现undefined

    console.log(bonly);  // 在变量声明前调用,输出为undefined
    var bonly;
    console.log(bonly);  // 变量未定义,输出为undefined
    console.log(typeof bonly);  // 所以检测类型,输出也为undefined
    

    3.'',""," ",都表示空值

    var bonly1='';
    var bonly2="";
    var bonly3=" ";
    console.log(bonly1);  // 什么也不输出
    console.log(bonly2);  // 什么也不输出
    console.log(bonly3);  // 什么也不输出
    console.log(typeof bonly1);  // string
    console.log(typeof bonly2);  // string
    console.log(typeof bonly3);  // string
    

    4.isNaN 判断参数是否不是数组,如果是数字返回false,不是数字返回true,注意的是isNaN函数会首先尝试将这个参数转换为数值,然后才会对转换后的结果是否是NaN进行判断。去看MDN解释

    console.log(isNan(1));
    console.log(isNaN("1")); // false
    console.log(isNaN("1n")); // true
    
    

    5.null与undefined的区别

    console.log(typeof null);        // object (因为一些以前的原因而不是'null')
    console.log(typeof undefined);   // "undefined"
    console.log(null === undefined); // false
    console.log(null == undefined);  // true
    console.log(null === null);      // true
    console.log(null == null);       // true
    console.log(!null);              // true
    console.log(isNaN(1 + null));    // false
    console.log(isNaN(1 + undefined)); // true
    

    6.''和""判断问题

    console.log(''===""); // true
    console.log(''===" "); // false
    console.log(null===""); // false
    console.log(undefined===""); // false
    console.log(undefined===undefined); // true
    

    7.查看项目中常见的取反判断

  • 相关阅读:
    重写对象的compareTo方法
    java基础之----hbase
    java基础之----innodb存储引擎
    java基础之----mysql存储结构
    fastjson jsonArrsy 转 list ,list 转 jsonArray
    java基础之----elasticsearch(Java客服端搜索实例)
    java基础之----elasticsearch
    java基础之----RabbitMQ
    java基础之----kafka
    java基础之----zookeeper
  • 原文地址:https://www.cnblogs.com/bonly-ge/p/9174487.html
Copyright © 2020-2023  润新知