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


最新文章

  1. 1、NASA Super Cloud Library(SCL)
  2. SQLServer中比较末尾带有空格的字符串遇到的坑
  3. php中htmlspecialchars和htmlentiti
  4. 【巩固】CSS3的3D动画 ——3D旋转(1)
  5. assembly打包。
  6. hdu 4268 Alice and Bob
  7. iOS深入学习(再谈block)
  8. CleanAOP实战系列--WPF中MVVM自动更新
  9. 恢复SD卡错删数据
  10. Python脚本控制的WebDriver 常用操作 <十六> 处理对话框
  11. Cannot Create Supplier Site (Address) (文档 ID 1069032.1)
  12. [转]hibernate主键生成策略
  13. 配置restful webservice 框架restkit
  14. RFC3489 STUN之客户端所处环境探测流程与部分属性含义说明
  15. 老李推荐:第1章3节《MonkeyRunner源码剖析》概述:架构
  16. 6、投资的一些思考 - CEO之公司管理经验谈
  17. bzoj 1835: [ZJOI2010]基站选址
  18. CSS代码检查工具stylelint
  19. Elastic Job学习
  20. [福大软工] Z班 软件工程实践总结 作业成绩

热门文章

  1. __del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数
  2. 游戏中的AOI(Area of Interest)算法
  3. v-modal的使用。
  4. 不识Netty真面目,只缘未读此真经
  5. Docker私服搭建--Harbor
  6. K8s (常用命令)
  7. 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。
  8. VIT Vision Transformer | 先从PyTorch代码了解
  9. docker(5)docker运行web应用
  10. Sqoop import export参数