xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

JavaScript null vs undefined

JavaScript null vs undefined

  1. null 变量已声明,但给变量分配空值;

  2. 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 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-07-23 19:05  xgqfrms  阅读(222)  评论(0编辑  收藏  举报