A const object can still change inside
In a normal script, writing to a frozen object is silently ignored. In strict mode it throws a TypeError instead.
A variable is a name that points to a value so you can use it later; declare it with const by default, with let when the value must change, and avoid the old var.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Declare a variable for a shop's name that never changes and one for the number of visitors, which starts at 0. Add 1 visitor twice, then log Hectal Shop has 2 visitors.
Fix this code so it runs: const price = 100; price = price - 20; console.log(price);
Which of these names are valid? firstName, 2ndPlace, _count, $total, class, my-score.
Explain it without notes
What is the difference between let, const and var?
If const variables can't change, why can you push into a const array?
Why do style guides say "const by default"?
What happens if you assign to a variable you never declared?
Console
(nothing was printed)Expected console output
{ name: 'Ravi', age: 31 }
Pune