Constants in JavaScript

  • Keyword ‘const’ is used to declare a constant in JavaScript.
  • A constant cannot be reassigned. Meaning we cannot change the value of a constant after its initial assignment.
  • A constant cannot be redeclared. Meaning we cannot change the type of constant after its declaration.
  • Value of a constant must be assigned at the time of declaration.

Declaring Constants

				
					// Creating 'A' as a constant with number value 
const A = 3.14

// Creating 'STR' as a constant with string value
const STR = "abcde"

// Creating 'GRADES' as a constant array
const GRADES = ['A','B','C']