In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "can constants in es6 be modified", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "can constants in es6 be modified"!
Constants in es6 cannot be modified; constants in es are declared using const, which is read-only and cannot be modified once declared; because const guarantees that the value cannot be modified, it guarantees that the data stored in the memory address pointed to by the constant cannot be changed, and the value of the basic data type constant is stored in the memory address.
Operating environment for this tutorial: Windows 10, ECMAScript version 6.0, Dell G3 PC.
Can I modify the ES6 constant?
definition of const: is a read-only constant, once declared, can not be modified
Is it really impossible to modify? Type in a few bits of code and look at it.
As can be seen from the above figure, after const defines string constant, try to modify it, and report the error 'Assignment to constant variable' and then type a few paragraphs of code to have a look
As can be seen from the above paragraphs of code, when the constant defined by const is 'basic data type', it cannot be modified; when the constant defined is' reference data type', we can modify the data through its attributes.
Why is this so?
Because the const constant guarantees that the value cannot be changed, it actually guarantees that the data stored in the memory address pointed to by the constant cannot be modified:
The value of the 'base datatype' is stored in the memory address, so the 'base datatype' defined by const cannot be changed.
The memory address pointed to by 'reference data type' is only a pointer, which points to the actual data through the pointer, that is, it is the pointer that cannot be changed, not the data, so the constant defined by const can modify the value through the attribute. This involves pop memory and heap memory.
As can be seen from the figure, variables and values of basic data types are in 'stack memory', and the memory address pointed to cannot be modified.
Variables referring to data types are stored in 'stack memory', values are stored in' heap memory', and pointers are used to point to corresponding values in 'heap memory', so the reference data type defined by const cannot be changed by' pointer', so values can be modified by attributes.
Thank you for reading, the above is "es6 constants can not be modified" content, after the study of this article, I believe that we can not modify the es6 constants have a deeper understanding of this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.