JavaScript: const, let, and var

Beginner JavaScript
Created by Best · 12.04.2026 at 16:05 UTC

In JavaScript, variables can be declared with var, let, or const.

var – function-scoped; can be redeclared. Avoid in modern code.

let – block-scoped; can be reassigned but not redeclared in the same scope.
let x = 1; x = 2; is fine.

const – block-scoped; must be initialized and cannot be reassigned.
const y = 1; y = 2; throws an error.
Note: for objects/arrays, the reference is constant but the contents can change (const arr = []; arr.push(1) is allowed).

Best practice: Prefer const by default; use let when you need to reassign.

University approvals: 0
Tasks
Question 1

Which declaration prevents reassignment of the variable?

Card Info
  • Topic: JavaScript
  • Difficulty: Beginner
  • Completed: 0 users
Creator
Best
Best
BestBuddy