let & var & initialized bug

what's wrong with this?

https://github.com/lydiahallie/javascript-questions#9-whats-the-output

  1. ReferenceError: greetign is not defined

  1. {}


solution

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#Strict_mode_for_modules

https://github.com/lydiahallie/javascript-questions/issues/33#issuecomment-521590062

let-initialize & ES module & "use strict"; bug

OK

// "use strict";

/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-08-15
*
* @description let-initialize-ok & ES module & "use strict"; bug
* @augments
* @example
* @link
*
*/ let log = console.log; const test = () => {
let greeting;
greetign = {}; // Typo!
log(greetign);
};
test();
// ??? greeting, not initialized
// ReferenceError: greetign is not defined const testComputed = () => {
var greetign = {}; // Typo!
let greeting;
log(greetign);
};
testComputed();
// {}

"use strict"; & bug

"use strict";

/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2019-08-15
*
* @description let-initialize & ES module & "use strict"; bug
* @augments
* @example
* @link
*
*/ let log = console.log; let greeting;
// greeting, not initialized // temporal dead zone,
// it is not accessible before the line we declare (initialize) it;
// When we try to access the variables before they are declared, JavaScript throws a ReferenceError. greetign = {}; // Typo! log(greetign);
// ReferenceError: greetign is not defined

scope & hoisting

https://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html

https://repl.it/@xgqfrms/Function-hoisting-greater-var-hoisting

https://stackoverflow.com/questions/7506844/javascript-function-scoping-and-hoisting

js var hoisting

  1. function

  2. var

https://www.sitepoint.com/5-typical-javascript-interview-exercises/



xgqfrms 2012-2020

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


let & var & initialized bug的更多相关文章

  1. impress.js 中文注释

    impress.js 中文注释 玄魂 /** * impress.js *(本翻译并未完全遵照原作者的注释翻译) * Impress.js 是受 Prezi启发,基于现代浏览器的 CSS3 与 Jav ...

  2. 拖动元素调换位置——sortable.js

    使用简介: https://github.com/SortableJS/Sortable https://segmentfault.com/a/1190000008209715 /**! * Sort ...

  3. overlay-3

    if(typeof Shadowbox=="undefined"){ throw"Unable to load Shadowbox, no base library ad ...

  4. 我对 impress.js 源码的理解

    源码看了两天,删掉了一些优化,和对 ipad 的支持,仅研究了其核心功能的实现,作以下记录. HTML 结构如下: <!doctype html> <html lang=" ...

  5. Spark RDD概念学习系列之rdd持久化、广播、累加器(十八)

    1.rdd持久化 2.广播 3.累加器 1.rdd持久化 通过spark-shell,可以快速的验证我们的想法和操作! 启动hdfs集群 spark@SparkSingleNode:/usr/loca ...

  6. ☀【组件 - 工具】Parallax 视差

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. Go 单例模式[个人翻译]

    原文地址:http://marcio.io/2015/07/singleton-pattern-in-go/ 最近几年go语言的增长速度非常惊人,吸引着各界人士切换到Go语言.最近有很多关于使用Rub ...

  8. Kotlin 类和对象

    类定义 Kotlin 类可以包含:构造函数和初始化代码块.函数.属性.内部类.对象声明. Kotlin 中使用关键字 class 声明类,后面紧跟类名: class Runoob { // 类名为 R ...

  9. 无锁编程 - Double-checked Locking

    Double-checked Locking,严格意义上来讲不属于无锁范畴,无论什么时候当临界区中的代码仅仅需要加锁一次,同时当其获取锁的时候必须是线程安全的,此时就可以利用 Double-check ...

随机推荐

  1. 使用JSONObject解析和生成json

    创建JSON 引用org.json包,推荐通过maven引用 1.直接构建 JSONObject obj = new JSONObject(); obj.put("sex", &q ...

  2. Language Guide (proto3) | proto3 语言指南(十四)选项

    Options - 选项 .proto文件中的单个声明可以使用许多 选项 进行注释.选项不会更改声明的总体含义,但可能会影响在特定上下文中处理声明的方式.可用选项的完整列表在google/protob ...

  3. kubenetes 相关命令(转载)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/xingwangc2014/article/details/51204224好久没写博客了,前段时间公 ...

  4. Linux系统对文件及目录的权限管理(chmod、chown)

    本文命令: 4 5 6 ls -l chmod chown 1.身份介绍 在linux系统中,对文件或目录来说访问者的身份有三种: ①.属主用户,拥有者(owner)文件的创建者 ②.属组用户,和文件 ...

  5. 4. Linux工作目录切换和文本文件编辑命令

    1.pwd:显示用户当前所处的工作目录 举例:[root@Centos ~]# pwd /root 2.cd:切换工作路径   "cd -"命令返回到上一次所处的目录 " ...

  6. 菜鸟初学Linux——Ubuntu系统中,用root权限进行复制粘贴操作

    long long ago,积累了一些Linux的小知识,拿出来分享一下,希望以后能够在工作上带来一些帮助. 方法一 第一步:打开终端,在命令行里输入sudo nautilus   第二步:输入你的用 ...

  7. 【疑】接入交换机lacp port-channel连接核心突然中断

    现状: 职场网络架构为接入交换机2个端口通过lacp协议的active模式组成port-channel上联到核心. 具体配置如下 接入: 核心: 故障现象: zabbix监控到核心交换机对应该接入交换 ...

  8. zabbix添加持续告警

  9. Educational Codeforces Round 97 (Rated for Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1437 A. Marketing Scheme 题解 令 \(l = \frac{a}{2}\),那么如果 \(r < ...

  10. AtCoder Beginner Contest 184 F - Programming Contest (双向搜索)

    题意:有一个长度为\(n\)的数组,你可以从中选一些数出来使得它们的和不大于\(t\),问能选出来的最大的和是多少. 题解:\(n\)的数据范围是\(40\),直接二进制枚举贴TLE,之前写过这样的一 ...