zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    今日总结
    今日总结
    今日总结
    k8s controller
    深入k8s:Informer使用及其源码分析
    理解 K8S 的设计精髓之 List-Watch机制和Informer模块
    Unix domain socket 简介
    Linux网络编程——端口复用(多个套接字绑定同一个端口)
    DPVS Tutorial
    dpvs route RTF_KNI
  • 原文地址:https://www.cnblogs.com/ming-os9/p/8889657.html
Copyright © 2011-2022 走看看