Learn JavaScript Basics

Master the fundamentals of JavaScript programming

Topics

Learning Progress

2 of 5 topics completed

📦Variables in JavaScript

JavaScript has three ways to declare variables:

Key Concept:

Variables are containers for storing data values.

  • varFunction-scoped variable declaration (older, less recommended)
  • letBlock-scoped variable declaration (can be reassigned)
  • constBlock-scoped constant declaration (cannot be reassigned)
// Variable examples let name = "John"; const age = 25; console.log(name); // Output: John name = "Jane"; // This works with let console.log(name); // Output: Jane // age = 26; // This would cause an error with const

💡 Pro Tip:

Use const by default, and only use let when you need to reassign the variable.

💻 Try it yourself

Output will appear here...

Tip: Press the Run Code button to execute your code

Lines: 2