Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 1.1 — Variables: let, const and var
JavaScript · Example 3 of 4

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.

01

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.

02

Fix this code so it runs: const price = 100; price = price - 20; console.log(price);

03

Which of these names are valid? firstName, 2ndPlace, _count, $total, class, my-score.

Explain it without notes

01

What is the difference between let, const and var?

02

If const variables can't change, why can you push into a const array?

03

Why do style guides say "const by default"?

04

What happens if you assign to a variable you never declared?

A const object can still change inside

Console

(nothing was printed)

Expected console output

{ name: 'Ravi', age: 31 }
Pune