0Pricing
Frontend Academy · Lesson

Variables: let const var and Scope

Declare variables with let, const, and var. Understand block scope, function scope, and why const is preferred for most values.

Why Variables?

Variables store values so you can reuse them, update them, and give them meaningful names. JavaScript has three ways to declare variables: var (old), let (modern, reassignable), and const (modern, constant binding).

const — The Default Choice

Declare with const when you won't reassign the variable. This signals intent and prevents accidental reassignment. Note: const prevents rebinding but doesn't make objects or arrays immutable.

const name = 'Alice';        // can't reassign
const PI = 3.14159;

const user = { age: 25 };    // object is mutable
user.age = 26;               // OK — property change, not rebinding
// user = {};               // Error — can't reassign const

All lessons in this course

  1. Variables: let const var and Scope
  2. Data Types: string number boolean null undefined
  3. Functions: declarations expressions arrow functions
  4. Control Flow: if else switch for while
← Back to Frontend Academy