当前位置:网站首页>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
边栏推荐
- Flask Mdict builds online MDICT Dictionary Service
- User login switching case
- adb shell ls /system/bin(索引表)
- 2022-07-19 advanced network engineering (XX) BGP route optimization, route optimization analysis one by one
- Babbitt | metauniverse daily must read: Tencent News suspended the sales service of digital collections, users left messages asking for a "refund", and phantom core also fell into the dilemma of "unsa
- UE5使用DLSS(超级采样)提升场景的 FPS 远离卡顿的优化方案
- One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
- SQL coding bug
- openresty lua-resty-core 使用
- 一文了解Pycharm快捷键
猜你喜欢
![[Numpy] 广播机制(Broadcast)](/img/1f/8d61ac7b35a82067bc0b77426590eb.png)
[Numpy] 广播机制(Broadcast)

adb shell ls /system/bin(索引表)

After working for bytek for two years, he got 15 offers at one go

Go --- automatic recompilation of air
![[program life]](/img/68/9a337d37490ad5cd75095cc5efd5e4.jpg)
[program life] "stage summary" - unwilling to be ordinary

SLIM:自监督点云场景流与运动估计(ICCV 2021)

Academic sharing | Tsinghua University, Kang Chongqing: power system carbon measurement technology and application (matlab code implementation)

一周活动速递|深入浅出第8期;Meetup成都站报名进行中

Why does Alibaba prohibit more than three forms from joining?

How to translate the address in the program?
随机推荐
Hexagon_V65_Programmers_Reference_Manual(5)
MySQL design optimization generates columns
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
DJI内推码(一码一用,2022年7月26日更新)
How to solve the problem of missing alarm information and synchronization when Haikang equipment is connected to easycvr?
Automatic test solution based on ATX
mcu日志输出的一种方法
认识网络模型TCPIP模型
《SRE:Google运维解密》读后有感
Arduino开发(二)_基于Arduino UNO开发板的RGB灯光控制方法
[numpy] array properties
Innovative cases | the growth strategy of digitalization of local life services and upgrading of Gaode brand
用户组织架构的管理
People call this software testing engineer. You're just making a living (with HR interview Dictionary)
To do the test, you have to go to the big factory and disclose the "hidden rules" of bat big factory recruitment internally
[Numpy] 数组属性
sql编码bug
Do you know about data synchronization?
API Gateway介绍
如何解决tp6控制器不存在:app\controller\Index