var, let, and const

var, let, and const: The Three Musketeers

JavaScript gives you three ways to declare variables, each with different behaviors and use cases.

var – The Old Timer

Copy to Clipboard

let – The Modern Hero

Copy to Clipboard

const – The Unchanging One

Copy to Clipboard

When to Use Each

  • const: Use by default for values that won’t change
  • let: Use when you need to change the value
  • var: Avoid in modern JavaScript

Remember: const prevents reassignment, not mutation of objects!