当前位置:网站首页>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边栏推荐
- In unity, opencv and QT are used to create a plugin (I)
- First modelarts training
- Gestionnaire de paquets d'Unit é Starting Server Stuck
- 29. location object
- Rule engine mode Net open source project case
- 2022-2028 current market situation and future development trend of thermopile Pyranometers in the world and China
- STL容器嵌套容器
- 电源防反接和防倒灌 - 使用MOS 管和运放实现理想二极管
- Rtd2171u, substitute for trd2171u, substitute for trd2171u, cs5261 C to hdmi4k_ 30Hz
- Unity screenshot
猜你喜欢

Usage methods and cases of PLSQL blocks, cursors, functions, stored procedures and triggers of Oracle Database

In 2021, the global ceramic substrate revenue will be about US $409.7 million, and it is expected to reach US $657.3 million in 2028

Role of RESNET residual block

10 R vector operation construction

Redis第四话 -- redis高性能原理(多路复用)和高可用分析(备份、主从)

Full list! 2022 Times Asia University Rankings announced!

unity package manager starting server stuck(Unity啟動卡在starting server,然後報錯)

Global Market Consulting - Research Report on the overall scale and application segmentation of the global HVDC converter station market in 2022

桌面以及文件资源管理器无限重启的解决

Database introduction
随机推荐
Première formation sur les largeurs modernes
Toolbar替换ActionBar后Title不显示
黑圆圈显示实现
In 2021, the global ceramic substrate revenue will be about US $409.7 million, and it is expected to reach US $657.3 million in 2028
Force buckle 6 Zigzag transformation
ICML 2022 𞓜 rethinking anomaly detection based on structured data: what kind of graph neural network do we need
26. 定时器
Two minutes to show you the charging standard of the Sub Ledger System
Full list! 2022 Times Asia University Rankings announced!
Introduction to jobrunr, a distributed background job scheduler - jaxenter
On scale of canvas recttransform in ugui
[unity plug-in] shader keyword analysis tool shadercontrol
15 r exercise
unity里面使用opencv,qt建立plugin(一)
29. location對象
UDP、TCP
14 r basic exercises
STL container nested container
2022-2028 current situation and future development trend of fuel cell market for cogeneration application in the world and China
2022-2028 current market situation and future development trend of thermopile Pyranometers in the world and China