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

JavaScript console.log Questions All In One

"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-08-01
 * @modified
 *
 * @description
 * @difficulty Easy Medium Hard
 * @complexity O(n)
 * @augments
 * @example
 * @link 
 * @solutions
 *
 */

const log = console.log;

hoisting & scope

https://developer.mozilla.org/en-US/docs/Glossary/Hoisting

https://developer.mozilla.org/en-US/docs/Glossary/Scope


(function() {
    var a = b = 5;
})();   
console.log(b);
console.log(a);
// 5
// Uncaught ReferenceError: a is not defined

// 等价于
var b;
// 全局作用域 global scope
(function() {
    // 变量提升 & function 作用域
    // hoisting & local scope
    var a;
    a = b;
    b = 5;
})(); 
// b, 可以访问到,且被赋值为 5
// a, IIFE 中定义的变量,外部访问不到,抛出引用错误
var x;
// 默认返回值 undefined
x
// undefined,如果没有给变量赋值,则为其赋值为默认值 undefined

var y = null;
// 默认返回值 undefined
y
// null,表示给变量赋值为空值 null

x == y
// true,值的意义都是都是空值
x === y
// false,值的意义相等,但是基本数据类型不同 (undefined, null)

x == false;
// false,值的意义不同,基本数据类型也不同
y == false;
// false,值的意义不同,基本数据类型也不同
z = `z`;
// "z"
z;
// "z"

refs

https://www.nowcoder.com/questionTerminal/73e735029f5a42ee9b63e57b017a1dcb?toCommentId=6812090&ran=80


Flag Counter

©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


原文地址:https://www.cnblogs.com/xgqfrms/p/13507772.html