Variables in JavaScript

CommentsData Types

Variables are containers for storing data values. They allow you to name and reuse pieces of information in your code.

In modern JavaScript (ES6+), we primarily use let and const. The older var is still supported but has some differences.

Declaring Variables

Use let for variables that can change, and const for values that should not be reassigned.

Reassignment

Variables declared with let can be reassigned. const variables cannot.

var – The Older Way

var is function-scoped and can be hoisted. Prefer let and const in modern code.

Naming Rules

  • Names must start with a letter, underscore (_), or dollar sign ($).
  • Subsequent characters can include numbers.
  • Names are case-sensitive.
  • Use camelCase for readability (e.g., myVariableName).

Basic Scope (Block vs Function)

let and const are block-scoped (limited to {} braces). var is function-scoped.

Quick Quiz

We have reviewed and checked the materials, but errors may still occur. The content is provided for educational purposes only, so use it at your own responsibility and verify with other sources if needed.

✨ Ask Lara — your AI study partner

Unlock personalized learning support. Lara can explain lessons, summarize topics, and answer your study questions — available from the Go plan and above.


Lara helps you learn faster — exclusive to ReadyTools Go, Plus, and Max members.

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.