Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use const in es6

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of how to use const in es6, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to use const in es6. Let's take a look at it.

In es6, const is used to declare a read-only constant, and the syntax is "const constant name = constant value;"; once a constant is declared, the value of the constant cannot be changed and is only valid in the block-level scope where the declaration is located, and the constant declared by the const command is not promoted and can only be used after the position of the declaration.

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

What is the use of const in es6

1. Const declares a read-only constant. Once declared, the value of the constant cannot be changed.

2. The scope of const is the same as that of the let command: it is valid only within the block-level scope in which the declaration is located.

3. The constant declared by the const command is not promoted and can only be used after the position of the declaration.

4. In ES6: the global variables declared by the var command and the function command are still the attributes of the top-level object; on the other hand, the global variables declared by the let command, the const command and the class command do not belong to the properties of the top-level object. That is, starting with ES6, global variables are gradually decoupled from the properties of the top-level object.

Let b = 1 ram / console output undefinedwindow.b

In JavaScript, const means "immutable" and is a keyword used to declare one or more constants. The declaration must be initialized, and the value can no longer be modified after initialization. If you change the value of a constant, it will cause a type error. The syntax is "const constant name = constant value;".

Once the identifier modified by the const has been assigned, it cannot be modified

Title / / 1. Note 1: once the identifier modified by const is assigned, it cannot be modified / / const name = 'tian'; / / will report an error: Uncaught TypeError: Assignment to constant variable. / / name = 'kim'; this is the end of the article on how to use const in es6. Thank you for reading it! I believe you all have a certain understanding of the knowledge of "how to use const in es6". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report