Preskoči na glavni sadržaj
Frontend je besplatan bonus na CodeMentor AI — glavni proizvod je Python. Registriraj se da spremiš napredak i otključaš svih 299 Frontend lekcija + 1,100+ Python lekcija.Registriraj se — besplatno
← ⚡ JavaScript & the browser·Modul C1 · Lekcija 2
ZadatakDeclare 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 i const: nikada ne koristite var

75 XP6 minFREE
Teorija

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:

  1. Reach for `const` first. If you're not planning to reassign, use const. It's the safer default.
  2. Use `let` when the value genuinely changes — a loop counter, a "current" pointer, a value built up step by step.
  3. Never use `var`. It exists for backward compatibility. var ignores 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 reassigned

const 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 defined

The {} braces are the boundary. var would have leaked inner to the surrounding function. let doesn't.

2 kartice
Pregled uživo
console output appears here…
← PrethodnaSljedeća lekcija →

Jedan Python ili web savjet dnevno — emailom

Kratko, ručno pisano, bez spama. Odjavi se jednim klikom.