var, let and const
In short: default to const — a name that can never be reassigned once
given a value. Use let when the name must point at something else later.
Leave var, the 1995 keyword, to old code: it ignores block braces and
allows quiet redeclaration, which hides mistakes. The one surprise: const
fixes the name, not the contents of an object or array behind it — you
can still change what's inside.

Track a song's play count
A playlist page needs a fixed title and a play count that goes up every
time the song finishes. Pick const for the name that never moves, let
for the one that does:
The count updates fine — let allows reassignment. The last line throws
TypeError: Assignment to constant variable. because title was declared
const. Note the count already printed 1 before the error: JavaScript
runs each line until it hits the one that fails, it does not undo what
already ran.
Grow a liked-songs list without touching its name
const blocks moving the name to a different value — it says nothing
about what lives inside an object or array:
This runs cleanly and prints 1. song still points at the exact same
object; only a property inside it changed. song = { title: "Red Dawn" }
would fail, because that line tries to point the name at a brand new
object — the one thing const forbids.
The song's title
"Blue Hour" never changes while the page runs. Never reassigned →
const title = "Blue Hour";
A const with no starting value
const must receive its value on the line it is declared — there is no
"decide later":
This throws SyntaxError: Missing initializer in const declaration before a
single other line of the program runs. let next; is legal and starts as
undefined; const total; is not legal at all.
Quick practice
What happens when const plays = 0; plays = 1; runs?
What does const song = { plays: 0 }; song.plays = 5; console.log(song.plays); log?
What happens with the line const total;?
Which keyword fits a counter that goes up by one after each song?
Which keyword lets you declare the same name twice in the same scope without any error?
🎯 Your turn
A playlist page needs: the playlist's fixed name, a volume the listener can change, and an array of liked songs that grows as they tap a heart. Declare each one and explain your choice of keyword.
Write your explanation and submit it — there's no code to run here, just your reasoning.
