const

noun

say it: “KONST” /kɒnst/

A JavaScript keyword for a variable that can't be given a new value.

What is const in JavaScript?

const — A keyword that declares a block-scoped variable that can't be given a new value. An object or array it holds can still change.

const taxRate = 0.08;
taxRate = 0.1;          // TypeError: Assignment to constant variable.

const cart = [];
cart.push("coffee");    // allowed: the array changes, the variable doesn't

In a sentence

  • “I declared the tax rate with const, so it can't be reassigned.”

Level: Novice · More JavaScript terms at this level

Updated

In other subjects