当前位置:网站首页>ES6 new variable modifiers let and const, new basic data type symbol
ES6 new variable modifiers let and const, new basic data type symbol
2022-07-28 05:16:00 【M78_ Domestic 007】
ES6 Brief introduction
ES6, Full name ECMAScript 6.0 , yes JavaScript The next version of the standard ,2015.06 release .
ES6 Mainly to solve ES5 The innate deficiency of , such as JavaScript There's no concept of class in it , But the current browser's JavaScript yes ES5 edition , Most advanced browsers also support ES6, But only achieved ES6 Part of the features and functions of .
New variable modifier let and const
let yes javascript Key words of
Its characteristics :
1、 Within a code block , Variable application let After keyword declaration , This code block has a local scope ( Called block level scopes ), This variable cannot be accessed outside the code block .
2、 You can declare that you do not assign values , But the variable declaration must be written before the access statement , Otherwise, an error will be reported .
3、 In the same block of code , Use of the let Declared variable name , Not enough to declare a variable name with the same name
Code display :
<script>
console.log(a)
let a=0;
// Application error
</script>
{
let a=0;
}
console.log(a)
{
let a
a=0
let a=9
}![]()
contrast var keyword :
1、var The declared variable has no scope
2、 You can declare that you do not assign values , You can also write the access before the declaration , Because there is precompiled , In the browser. js This variable is implicitly declared in advance when the engine scan script is executed .
3、 You can declare two variable names with the same name at the same time
const yes JS A constant modifier of
var and let The value of the declared variable can be modified , and const Once the declared variable is assigned, it cannot be changed , When it is used to declare variables at the same time , It must be initialized, otherwise an error will be reported , Often used for modular development .
It is associated with let Same keyword , The code block of the variable declared with it will form a block level scope , At the same time in the same code block , You cannot declare two identical variable names at the same time
const Declared object , The value of the object can be modified and increased , Because it is a reference object , It is a storage space , The storage space does not change when the value is modified .
symbol
ES5 The basic data types of are number、boolean、string、undefined、null
ES6 New basic data type , Used to ensure the uniqueness of a data , Avoid repetition in the program .
Illustrate with examples :
<script>
var re=symbol("aaa")
var re2=symbol("aaa")
console.log(re==re2)//false
// Come to the conclusion : Even if the values of two numbers are the same , But it is symbol The data is not equal .
</script>边栏推荐
- 【ARXIV2204】Simple Baselines for Image Restoration
- HashSet add
- Do you know several assertion methods commonly used by JMeter?
- HDU 3585 maximum shortest distance
- CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?
- 【CVPR2022】On the Integration of Self-Attention and Convolution
- App test process and test points
- I interviewed a 38 year old programmer and refused to work overtime
- 【CVPR2022】Multi-Scale High-Resolution Vision Transformer for Semantic Segmentation
- 多御安全浏览器将改进安全模式,让用户浏览更安全
猜你喜欢

为什么md5不可逆,却还可能被md5免费解密网站解密

CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?

MySQL(5)

【ARXIV2204】Simple Baselines for Image Restoration

从微服务基本概念到核心组件-通过一个实例来讲解和分析

【ARXIV2205】Inception Transformer

Evolution of ape counseling technology: helping teaching and learning conceive future schools

Program life | how to switch to software testing? (software testing learning roadmap attached)
![Classes and objects [medium]](/img/0a/955d00d63f06e7e15e946599628edf.png)
Classes and objects [medium]

Check box error
随机推荐
Anaconda common instructions
POJ 2763 housewife wind (tree chain partition + edge weighting point weight)
Supervisor series: 5. Log
Making RPM packages with nfpm
塑料可以执行GB/T 2408 -燃烧性能的测定吗
HDU 1914 the stable marriage problem
Can plastics comply with gb/t 2408 - Determination of flammability
微服务故障模式与构建弹性系统
Have you learned the common SQL interview questions on the short video platform?
HashSet add
Interpreting the source code of cfrunloopref
[high CPU consumption] software_ reporter_ tool.exe
jsonp 单点登录 权限检验
What is the reason why the easycvr national standard protocol access equipment is online but the channel is not online?
基于MPLS构建虚拟专网的配置实验
How to simulate common web application operations when using testcafe
【ARXIV2203】CMX: Cross-Modal Fusion for RGB-X Semantic Segmentation with Transformers
Internal implementation principle of yymodel
Duoyu security browser will improve the security mode and make users browse more safely
CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?