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

JavaScript console.log Questions All In One

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



©xgqfrms 2012-2020

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


posted @   xgqfrms  阅读(149)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-08-15 let & var & initialized bug
2019-08-15 Micro Frontends & microservices
2019-08-15 js bitwise operators
2018-08-15 钉钉-开放平台 & 微信 share
2016-08-15 面试秘籍:如何在面试前判断一家公司靠不靠谱? All In One
点击右上角即可分享
微信分享提示