Saltar para o conteúdo principal
O Frontend é um bônus gratuito no CodeMentor AI — o produto principal é Python. Cadastre-se para salvar seu progresso e desbloquear todas as 299 lições de Frontend + 1,100+ lições de Python.Cadastre-se — grátis
← ⚡ JavaScript & the browser·Módulo C1 · Lição 2
TarefaDeclare 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 e const: nunca use var

75 XP6 minFREE
Teoria

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 separadores
Pré-visualização ao vivo
console output appears here…
← AnteriorPróxima lição →

Recebe uma dica de Python ou web por dia — por email

Curto, escrito à mão, sem spam. Cancela a subscrição num clique.