⊗jsPmBsCn 42 of 504 menu

Constants in JavaScript

In addition to variables in JavaScript, you can also create constants. They can only be written to once, and then their values cannot be changed. Constants are declared using the operator const.

Typically, constants are used for values that should not be accidentally changed in code. For example, let's create the constant that will store the value of pi:

const pi = 3.14;

Constants are usually written in capital letters so that they can be distinguished from regular variables:

const PI = 3.14;

Let's try to change the value of our constant:

const PI = 3.14; PI = 3; // throws an error

Create the constant PI and use it to calculate the circumference with a given radius.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline