JavaScript · Level 1 Basics

let & const

Store values with let when they will change and const when they won't, and see what JavaScript does when you try to reassign a constant.

  • let declares a variable you can reassign
  • const declares a constant
  • Reassigning a const throws a TypeError

Use let for a value that will change and const for one that won't. The trap: reassigning a const is not ignored, it crashes with a TypeError.

let visits = 1;
visits = 2;              // fine: let can change

const SITE = "LearnMap";
SITE = "Other";          // TypeError: Assignment to constant variable.

Declare the constant SITE_NAME set to "LearnMap", then write pageTitle(page) that returns "<page> | LearnMap" using it, e.g. pageTitle("Home") returns Home | LearnMap.

solution.js
Test Suites Pending
Output