Get the App
SLTechnology News&Howtos  ›  Development  › 

How to define constants in javascript

Shulou Source: shulou.com Published: 2022-06-02 18:21:13 11月16日 Update

This article mainly explains "how to define constants in javascript". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to define constants in javascript.

Javascript can use the const keyword to define constants, the keyword can define one or more constants, the definition must be initialized, and the initialization value can no longer be modified; syntax "const variable name = value;" or "const variable name 1 = value 1, variable name 2 = value 3, variable name n = value n;"

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

A constant is a quantity that cannot be changed and is usually used to store data that is neither changed nor desired; the value of the constant remains unchanged throughout the running of the script code and cannot be re-modified.

In javascript, you can use the const keyword to define constants.

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.

Example:

Try {const PI = 3.141592653589793; PI = 3.14;} catch (err) {document.getElementById ("demo") [xss_clean] = err;} Thank you for your reading, the above is the content of "how to define constants in javascript". After the study of this article, I believe you have a deeper understanding of how to define constants in javascript. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Constants variables keywords keywords learning running content multiple that is data syntax storage code just containers ideas situations tutorials articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Shulou Information Apple Shulou Tech Info