← Back to Roadmap

Constants (const)

Easy

In plain terms

const declares a constant - a variable whose binding cannot be reassigned. Use const by default; only use let when you need to reassign. Objects/arrays declared with const can still have their contents modified.

What you need to know

  • Cannot reassign
  • Object/array contents can change
  • Prefer const over let

Try it yourself

Copy the code below and run it in your browser console or a code editor:

const MAX = 100;
// MAX = 200;  // Error!

const user = { name: 'John' };
user.name = 'Jane';  // OK - object content can change
// user = {};        // Error - cannot reassign user

const nums = [1, 2, 3];
nums.push(4);  // OK
// nums = [];   // Error

Learn more

Dive deeper with these trusted resources: