Overview
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
Short Course
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.
Task
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.
Test Suites
Pending
Next
Output