Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the constant in javascript

Shulou Source: shulou.com Published: 2022-06-02 11:17:15 09月24日 Update

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.

Tags: Constant variable character string that is quotation marks Boolean data article keyword content decimal more knowledge grammar run good practical two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei macOS Xiaomi MariaDB