当前位置:网站首页>let、const、var之间的用法以及区别
let、const、var之间的用法以及区别
2022-07-27 05:03:00 【weixin_46051260】
1)var
- 使用var声明的变量即是顶级变量(window对象的属性),也是全局变量
- 使用var声明的变量存在变量提升的情况
- 使用var可以对一个变量进行多次声明,后面的声明会覆盖前面的变量声明
- 在函数中再次使用var声明这个变量的时候,这个变量就是局部的,如果直接a=1,那就是全局变量
2)let
- let所声明的变量只在let命令所在的代码块中生效
- let不存在变量提升
- let不允许在相同的作用域下重复声明
3)const
- const声明一个只读的常量,一旦声明,常量的值就不能改变(实质上是存储地址的值不能改变)
- const一旦声明,就必须赋值
- 此外参考let
边栏推荐
- Makefile 通俗易懂详解
- Li Hongyi machine learning team learning punch in activity day06 --- convolutional neural network
- 如何将Excel表格中的多列内容合并到一列
- Dnsmasq Usage Summary
- Pytorch installation new pit
- 程序环境和预处理(上):一个程序是怎么成功运行的?
- Share a multiple-choice question about the process of program compilation (including a brief discussion on the compilation process, the formation and merging process of symbol tables)
- C language makes a small maze
- SQL database → constraint → design → multi table query → transaction
- Flask框架创建项目初期总结
猜你喜欢

初识C语言——常见的数据类型

The concept of cloud native application and 15 characteristics of cloud native application

如何将Excel表格中的多列内容合并到一列

JDBC API details

Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)

Li Hongyi machine learning team learning punch in activity day03 --- error and gradient decline

分享力扣—189.轮转数组 的三种解法

C WPF uses listbox to implement ruler control

Li Hongyi machine learning team learning punch in activity day04 - Introduction to deep learning and back propagation mechanism

Li Hongyi machine learning team learning punch in activity day01 --- introduction to machine learning
随机推荐
Student management system
创建项目 实现登录注册,生成jwt,发送验证码
js轮播图
How to quickly and effectively solve the problem of database connection failure
【codeforces 1695C Zero Path】DP
用户管理-分页
后台频道组管理功能实现
软件测试面试题(重点)
Flask的使用
Program environment and preprocessing (Part 2): define, undef, command line compilation, conditional compilation, file inclusion (super full collation, recommended collection!!!
背景图片相关应用-铺满,自适应
C语言入门介绍
通用视图,DRF视图回顾
C语言中堆内存介绍和管理
Redis cluster
flask项目配置
Day5 --- Flask-RESTful请求响应与SQLAlchemy基础
规格管理,及规格选项管理功能实现
js基础练习题
The concept of cloud native application and 15 characteristics of cloud native application