In JavaScript you can declare a constant just as you declare a variable. The value of the constant can not change within the script. Constants are declared using const instead of var.

Constants can have the same types of values, string, number or boolean.

Constants can not have the same identiier (name) as any of the variables in the script.

Rules for naming constants

Constants have the same rules for what can be inluded in the identifier.

  • Constant names, also called identifiers, can consist of uppercase and lowercase letters, numbers, dollar signs $ and underscores _.
  • The constant name must start with an underscore _, a letter or a dollar sign $. It can not start with a number.
  • JavaScript is case sensitive. You must be consistant with the use of lowercase or uppercase when you use the constant later on in the script.
  • You cannot use dashes - in identifiers or other characters

Three dot cartouche

Examples for naming constants within JavaScript

const intRate = 0.0654;
const fullHeight = 456;
const clientName = "The Hartford Group";
const n = 18;
const testResult = true;