Skip to main content

Variables: var, let and const

Learn Variables: var, let and const (Phase 1 · Fundamentals, Variables, Data Types, Operators (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Declaring variables • A variable is a named container for a value. JavaScript has three keywords: var (old, function-scoped), let (block-scoped, reassignable) and const (block-scoped, cannot be reassigned). • Use const by default, let when the value must change, and avoid var in new code. • const prevents re-assignment , not mutation: a const object or array can still have its contents changed. • Names are case-sensitive, may contain letters, digits, _ and $ , and cannot start with a digit. Use camelCase for variables and UPPER_SNAKE_CASE for true constants.

More lessons in Phase 1 · Fundamentals, Variables, Data Types, Operators (Essential)