const

const

  • Stands for constant

  • These are variables for which its value does not change after it has been assigned an initial value

  • This help make your code easier to debug and protects certain values from accidentally being overridden in your codebase


Declaring a constant

const are the same as let but with one key difference, values can only be assigned once to a const variable

// declare a const named 'school'
const school = "General Assembly";

An error will occur if you try to update the value of a const


// correctly declare a constant using "const" keyword
const greeting = "Hello";


// const values cannot be updated, if you attempt to do so
// an error will occur

greeting = "Good Morning"; // this will throw an error

inline