当前位置:网站首页>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边栏推荐
- Interface isolation principle
- Introduction to jobrunr, a distributed background job scheduler - jaxenter
- The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
- Two end carry output character
- Unity screenshot
- 2022-2028 global and Chinese thermal power generation (TEG) module market status and future development trend
- The tutor transferred me 800 yuan and asked me to simulate a circuit (power supply design)
- ICML 2022 𞓜 rethinking anomaly detection based on structured data: what kind of graph neural network do we need
- moderlarts第一次培训
- R 16 basic exercises
猜你喜欢

Role of RESNET residual block

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

Flutter Doctor affiche les solutions que xcode n'a pas installées

The first bullet of comparative learning

Object storage of CEPH distributed storage

29. location對象

Black circle display implementation

Solution to unlimited restart of desktop and file explorer

ICML 2022 𞓜 rethinking anomaly detection based on structured data: what kind of graph neural network do we need

周鸿祎:想做直播带货抹不下面子 数据勒索成突出的安全威胁
随机推荐
QQ贴吧那种图片一点开,就变了的原理
moderlarts第一次培訓
Current situation and future development trend of hot isostatic pressing service market in the world and China from 2022 to 2028
Capriccio in the Internet Age
27. this pointing problem
银泰百货与淘宝天猫联合打造绿色潮玩展,助力“碳中和”
STC 纯硬件自动下载电路 V2
moderlarts第二次作业
【计算机推免】哈尔滨工业大学物联网与泛在智能研究中心面向全国高校推免生招收2023级研究生(硕、博、直博生)
First modelarts training
Force buckle 6 Zigzag transformation
On scale of canvas recttransform in ugui
Flutter Doctor affiche les solutions que xcode n'a pas installées
Unified exception handling
Figure guessing game
Final examination of theory and practice of socialism with Chinese characteristics 1
moderlarts第一次培训
STL container nested container
What is the essence and process of SCM development? Chengdu Automation Development Undertaking
[Unity插件]着色器关键字分析工具ShaderControl