JavaScript null vs undefined
JavaScript null vs undefined
-
null 变量已声明,但给变量分配空值;
-
undefined 变量已声明,但尚未分配任何值;
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-07-23
* @modified
*
* @description null vs undefined
* @difficulty Easy
* @complexity O(n)
* @augments
* @example
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined
* @solutions
*
*/
const log = console.log;
// null 变量已声明,但给变量分配空值;
// undefined 变量已声明,但尚未分配任何值;
const obj = { k1: undefined, k2: null, };
// {k1: undefined, k2: null}
const {
k1,
k2,
} = obj;
k1;
// undefined
k2;
// null
log(`k1 =`, k1)
log(`k2 =`, k2)
// k1 = undefined
// k2 = null
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13368136.html
未经授权禁止转载,违者必究!