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. JVM笔记 -- Java跨平台和JVM跨语言

    学习JVM的重要性 从上层应用程序到底层操作系统,到底有哪些东西? 平时开发的应用程序主要基于各种框架,譬如Spring,SpringMVC,Mybatis,而各种框架又是基于Java API来实现的 ...

  2. Spring Boot 之遇见JSON

    MVC框架中,Spring Boot内置了jackson来完成JSON的序列化和反序列化操作,并且,在与其他技术集成的时候,如Redis.MongoDB.Elasticsearch等对象序列化,都可使 ...

  3. linux 高可用----keepalived+lvs

    什么是高可用? HA(high availability)即高可用性:就是在高可用集群中发生单点故障时,能够自动转移资源并切换服务,以保证服务一直在线的机制. LVS LVS:(linux virtu ...

  4. dedecms后台更新网站栏目无反应的解决方法

    dedecms进行第二次模板开发后,遇到在栏目更新的时候没有反应,但是用回原来的初始模板就可以,百度查找了很多的教程也无法进行解决,就这样慢慢的摸索.终于找到了问题的所在,原因可能是该更新的时候无法获 ...

  5. Flink-v1.12官方网站翻译-P009-Event-driven Applications

    事件驱动的应用 处理函数 简介 ProcessFunction将事件处理与定时器和状态结合起来,使其成为流处理应用的强大构件.这是用Flink创建事件驱动应用的基础.它与RichFlatMapFunc ...

  6. validate插件

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

  7. CodeForces 1119D(差分+前缀和+二分)

    题意:给你一个数组,数组每次每个数都+1,有q次查询每一查询+L到+R中出现的所有不重复的数字个数. +L到+R其实就相当于是0到+(R-L+1) 感觉自己写的好啰嗦,直接上代码加注释: 1 #inc ...

  8. Codeforces Round #697 (Div. 3) G. Strange Beauty (DP,数学)

    题意:给你一组数,问你最少删去多少数,使得剩下的数,每个数都能整除数组中其它某个数或被数组中其它某个数整除. 题解:我们直接枚举所有因子,\(dp[i]\)表示\(i\)在数组中所含的最大因子数(当我 ...

  9. zoj3777 Problem Arrangement(状压dp,思路赞)

    The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...

  10. Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! A、Johnny and Ancient Computer B、Johnny and His Hobbies C、Johnny and Another Rating Drop

    题目链接:A.Johnny and Ancient Computer 题意: 给你两个数a,b.问你可不可以通过左移位运算或者右移位运算使得它们两个相等.可以的话输出操作次数,不可以输出-1 一次操作 ...