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

What is the constant in javascript

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

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail what the constant is in javascript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

In javascript, variables that can no longer be modified once defined are called constants. Constants represent some fixed data and are values that cannot be modified. The keyword that defines a constant is const, which must be initialized when defined, and the value cannot be modified after initialization. The syntax "const variable name = value;"

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

In javascript, variables that can no longer be modified once defined are called constants.

Constants represent fixed data and are values that cannot be modified; constants can only be read and cannot be modified.

The key word of the constant is const:

Const can define one or more constants, which must be initialized at the time of definition, and the value cannot be modified after initialization.

Syntax:

Const variable name = value; const variable name 1 = value 1, variable name 2 = value 3, and variable name n = value n

Note: constants, like variables, are containers for storing data, except that the value of the constant cannot be changed during the run of the program, otherwise an error will be reported at run time.

Const NUM = 666 NUM / NUM = 888; / / if you try to modify the value of the constant NUM, you will find that there is an error. Once the constant is defined, you can no longer change the value of console.log (NUM).

Extended knowledge: classification of constants in JavaScript

Integer constant

An integer constant is actually a positive number, and any integer written in JavaScript is an integer constant.

1 / 666 / 99

Real constant

A real constant is actually a decimal, and any decimal written in JavaScript is a real constant.

3.14 / 6.66

String constant

A string constant is actually something enclosed in single or double quotation marks, which we call a string constant.

'a'

'abc'

"1"

"BNTang"

Note: no matter how many characters are enclosed in single or double quotation marks, they are string constants in JavaScript

Boolean constant

Boolean constants are actually true or false, expressed by true and false in JavaScript

Boolean constants have only two values in JavaScript, true (true) or false (false)

Custom constant

New to ES6

Const constant name = constant value; this is the end of the article on "what is a constant in javascript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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