当前位置:网站首页>var 和 let的区别_let 和 var的区别
var 和 let的区别_let 和 var的区别
2022-06-11 20:37:00 【天马3798】
js定义变量前言
1.js 定义变量 使用 var 或者let
2.js定义常量 使用 const
3.var 定义变量是用js语言诞生就有的; let定义变量是从ES6新语法开始的。
4.let定义变量,符合常规强类型语言定义变量逻辑,新定义再使用+不能重复生命。
var 和 let的区别_let 和 var的区别整理如下:
一、作用域级别不同
var是函数级作用域
let只能是块级作用域,跟C#等强类型变量作用域一样。
在函数中声明了var,整个函数内都是有效的,比如说在for循环内定义的一个var变量,实际上其在for循环以外也是可以访问的。
而let由于是块作用域,所以如果在块作用域内定义的变量,比如说在for循环内,在其外面是不可被访问的,所以for循环推荐用let。
代码片段:
//for循环的{} 是块级作用域
for (var i = 0; i < 10; i++) { }
console.info(i); //打印:10
for (let j = 0; j < 10; j++) { }
console.info(j); //j is not defin边栏推荐
- 周刊02|不瞒你说,我其实是MIT的学生
- First modelarts training
- 2022-2028 global and Chinese thermopile and microbolometer infrared detector Market Status and future development trend
- The principle that the picture of QQ Post Bar changes when it is opened
- In 2021, the global revenue of Indian fragrant rice was about $12530 million, and it is expected to reach $21670 million in 2028
- 13 r basic exercises
- 29. location對象
- STL container nested container
- A mechanics informed artistic neural network approach in data driven constructive modeling
- Flutter doctor shows the solution that Xcode is not installed
猜你喜欢

Compilation process of program

Modify appid of local wechat applet

Gestionnaire de paquets d'Unit é Starting Server Stuck

27. this指向问题

电源防反接和防倒灌 - 使用MOS 管和运放实现理想二极管

导师转我800块,让我仿真一个电路(电源设计)

秀创意,赢显卡!MMPose姿态估计创意大赛震撼来袭

unity package manager starting server stuck(Unity启动卡在starting server,然后报错)

Wechat applet | rotation chart

桌面以及文件资源管理器无限重启的解决
随机推荐
Interviewer: what is the event flow and event model in JS?
Research and Analysis on the market status of polybutene-1 in China from 2021 to 2027 and forecast report on its development prospect
Full list! 2022 Times Asia University Rankings announced!
上海内推 | 上海期智研究院于洋老师课题组招收全职研究员
Current situation and future development trend of thermoelectric generator Market in the world and China from 2022 to 2028
Database introduction
These postgraduate entrance examination majors are easy to be confused. If you make a mistake, you will take the exam in vain!
周鸿祎:想做直播带货抹不下面子 数据勒索成突出的安全威胁
[Err] 1045 - Access denied for user ‘root‘@‘%‘ (using password: YES)
UI automated interview questions
Modelarts second job
STC hardware only automatic download circuit V2
Installation and performance test of Apache APIs IX on Amazon graviton3
2022-2028 current situation and future development trend of fuel cell market for cogeneration application in the world and China
Final examination of theory and practice of socialism with Chinese characteristics 1
Capriccio in the Internet Age
2022-2028 current market situation and future development trend of thermopile Pyranometers in the world and China
秀创意,赢显卡!MMPose姿态估计创意大赛震撼来袭
8 r subset
STL容器嵌套容器