Frontend is a free bonus on CodeMentor AI — the main product is Python. Register to save your progress and unlock all 290 Frontend lessons + 1,000+ Python lessons.Sign up — free
TaskDeclare three names: const APP_NAME set to 'CodeMentor', let counter set to 0, and inside a separate { } block use let inside set to 'private'. After the block, log APP_NAME, counter, and a literal string 'done' (do not log 'inside' — that should not be in scope).
let and const: never use var
75 XP6 minFREE
Theory
Two ways to name a value in 2026
const PI = 3.14; // I'm never reassigning this let counter = 0; // I will reassign this counter = counter + 1; // OK
Rules of thumb that hold up in production:
- Reach for `const` first. If you're not planning to reassign, use
const. It's the safer default. - Use `let` when the value genuinely changes — a loop counter, a "current" pointer, a value built up step by step.
- Never use `var`. It exists for backward compatibility.
varignores block scope, leaks into surrounding functions, and is hoisted in ways that hide bugs. If you see it in code from before 2017, that's why.
const doesn't mean immutable
A common surprise:
const user = { name: "Anna" };
user.name = "Boris"; // OK, the OBJECT is mutated
user = {}; // ERROR, the BINDING can't be reassignedconst locks the binding — what variable name points to. It doesn't freeze the value inside. Object.freeze() is the next-level lock if you need that.
Block scope, not function scope
if (true) {
let inner = 10;
}
console.log(inner); // ReferenceError: inner is not definedThe {} braces are the boundary. var would have leaked inner to the surrounding function. let doesn't.
Live preview
console output appears here…