0Pricing
JavaScript Academy · Lesson

let, const, and avoiding var

let and const basics, why to avoid var, block scope, and a gentle intro to the temporal dead zone (TDZ).

Intro

Goal: Use let and const confidently, avoid legacy var, and understand block scope and TDZ.

  • let vs const
  • Block scope
  • TDZ safety
let, const, and avoiding var — illustration 1

let vs const basics

Rule: Use const unless you plan to reassign; otherwise choose let.

// Prefer const by default; use let when you need to reassign
const appName = "CoddyKit";   
// cannot reassign
let score = 0;                
// can reassign

score = score + 1;
console.log("App:", appName);
console.log("Score:", score);
let, const, and avoiding var — illustration 2

All lessons in this course

  1. let, const, and avoiding var
  2. Block/Function/Module Scope and the TDZ
  3. Naming, Readability, and Common Pitfalls
← Back to JavaScript Academy