当前位置:网站首页>Uncaught SyntaxError: redeclaration of let page
Uncaught SyntaxError: redeclaration of let page
2022-07-27 18:28:00 【梦凝哲雪】
未捕获的语法错误:let页的重新声明
Uncaught SyntaxError: redeclaration of let page
ES6中 出现了用 let 关键字 完善了 JS的作用域概念
声明变量并赋值 打印
let page = 1;
console.log( page ); // 1
在之前我们习惯 var 声明 同样的变量名 可以覆盖
var rows = 10;
console.log( rows ); // 10
var rows = 20;
console.log( rows ); // 20

let 重复声明同样的变量名 时i 直接 报错
let rows = 10;
console.log( 10 );
let rows = 20;

常用于循环遍历时
var声明时 循环结束依然能够访问 循环中的 定义的 i 值
for( var i = 1; i <= 3; i++){
console.log( i );
}
console.log( i ); // 4
等价于变量提升效果 此时 i 相当于 全局变量
var i;
for( i = 1; i <= 3; i++){
console.log( i );
}
console.log( i ); // 4

为了避免该问题 let 声明 即可 单独作用域
for( let i = 1; i <= 3; i++){
console.log( i );
}
console.log( i );

此时 超出 for 循环的范围 变量 i 因超出当前作用域显示未定义
Uncaught ReferenceError: i is not defined
边栏推荐
猜你喜欢

82.(cesium篇)cesium点在3d模型上运动

【深度学习】Pytorch torch.autograd 自动差分引擎

Arduino development (II)_ RGB light control method based on Arduino uno development board

好开不贵,舒适安全!深度体验比亚迪宋Pro DM-i

金仓数据库 Oracle 至 KingbaseES 迁移最佳实践 (4. Oracle数据库移植实战)

Management of user organization structure
![[dart] a programming language for cross end development](/img/e1/1167a322bb9f276f2e00fb12414d17.png)
[dart] a programming language for cross end development
![[Numpy] 广播机制(Broadcast)](/img/1f/8d61ac7b35a82067bc0b77426590eb.png)
[Numpy] 广播机制(Broadcast)

Where is the program?

hcip第五天
随机推荐
全局样式与图标
LabVIEW学习笔记五:按钮按下后无法返回原状
[dart] a programming language for cross end development
Express WEB服务器的简单使用
Onion group joined hands with oceanbase to realize distributed upgrading, and global data has achieved cross cloud integration for the first time
hcip第五天
R语言使用t.test函数执行t检验验证总体均值是否是某个特定的值(从样本集推论总体均值)
Introduction to rk3399 platform introduction to proficient series (Introduction) 21 day learning challenge
一文了解Pycharm快捷键
MySQL基本查询和运算符
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
adb shell ls /system/bin(索引表)
IOU 目标跟踪其一:IOU Tracker
认识网络模型网络模型概述
[Numpy] 数组索引和切片
Vant component library
NPDP|什么样的产品经理可以被称为优秀?
金仓数据库 Oracle 至 KingbaseES 迁移最佳实践 (4. Oracle数据库移植实战)
JVS公众号登陆配置
《SRE:Google运维解密》读后有感