• Null 和 undefined 的区别


    null 表示一个值被定义了,定义为“空值”

    undefined 表示根本不存在定义。

    1:

    所以设置一个值为null 是合理的, obj.value = null;  正确

    设置一个值为undefined是不合理的  obj.value = undefined; 错误

    2:

    null预定义为一个object 值为空。 undefined预定义为全局变量,值为undefined。

    1 typeof null; //object
    2 typeof undefined; // undefined

    3:

    转义 

    1 !!(null);//false
    2 !!(undefined);//false
    3 Number(null);// 0
    4 Number(undefined);// NaN
    5 null == undefined; // true
    6 null === undefined; // false

    4:

    判定

    1 isNull = function (obj){ return obj === null;}
    2 isUndefined = function(obj){ return obj === void 0;}

    5:

    用法

    5.1 

     1  null 常用来定义一个空值
     2 
     3  undefined :
     4 5.1变量声明了未赋值 
     5 var test;
     6 console.log(test);// undefined
     7 
     8 5.2 调用函数时,没提供应该提供的参数,参数为undefined
     9 function(lists){...}// lists 未提供
    10 
    11 5.3 对象没有赋值的属性,该属性为undefined
    12 var test={};
    13 console.log(test.aaa);//undefined
    14 5.4 函数没有返回值时,返回undefined
    15 function test(){}
    16 test();//undefined
  • 相关阅读:
    【声纹识别】 kaldi callhome diarization
    python3 类型提示
    公钥私钥,HTTPS,HTTP通俗讲解
    一图学会MySQL的JOIN
    链表翻转(看图学)
    如何理解 Python 的赋值逻辑
    Python十大排序算法
    Python-functools (reduce,偏函数partial,lru_cache)
    Python-类型注解(3.5引入)
    Python-装饰器
  • 原文地址:https://www.cnblogs.com/ming-os9/p/8889657.html
Copyright © 2020-2023  润新知