let & var & initialized bug
2024-10-19 07:00:13
let & var & initialized bug
what's wrong with this?
https://github.com/lydiahallie/javascript-questions#9-whats-the-output
- ReferenceError: greetign is not defined
- {}
solution
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
function
var
https://www.sitepoint.com/5-typical-javascript-interview-exercises/
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
最新文章
- 1、NASA Super Cloud Library(SCL)
- SQLServer中比较末尾带有空格的字符串遇到的坑
- php中htmlspecialchars和htmlentiti
- 【巩固】CSS3的3D动画 ——3D旋转(1)
- assembly打包。
- hdu 4268 Alice and Bob
- iOS深入学习(再谈block)
- CleanAOP实战系列--WPF中MVVM自动更新
- 恢复SD卡错删数据
- Python脚本控制的WebDriver 常用操作 <;十六>; 处理对话框
- Cannot Create Supplier Site (Address) (文档 ID 1069032.1)
- [转]hibernate主键生成策略
- 配置restful webservice 框架restkit
- RFC3489 STUN之客户端所处环境探测流程与部分属性含义说明
- 老李推荐:第1章3节《MonkeyRunner源码剖析》概述:架构
- 6、投资的一些思考 - CEO之公司管理经验谈
- bzoj 1835: [ZJOI2010]基站选址
- CSS代码检查工具stylelint
- Elastic Job学习
- [福大软工] Z班 软件工程实践总结 作业成绩
热门文章
- __del__ PyPy和CPython的不同点 动态编译(注意不是解释) 析构函数被调用的次数
- 游戏中的AOI(Area of Interest)算法
- v-modal的使用。
- 不识Netty真面目,只缘未读此真经
- Docker私服搭建--Harbor
- K8s (常用命令)
- 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。
- VIT Vision Transformer | 先从PyTorch代码了解
- docker(5)docker运行web应用
- Sqoop import export参数