Variables

Think about your mobile phone. It keeps your contacts, your photos, your battery percentage, and whether Wi-Fi is on or off. All of this is data, and each piece is a different kind of data.

JavaScript also works with data all the time. To use data, we first need a place to keep it, and we need to know what kind of data it is. That is what this lesson is about.

Variables: A Quick Introduction

A variable is like a container with a sticker on it. The sticker is the name, and inside the container is the value.

  • studentName and marks are the names.
  • "Anjali" and 92 are the values.

JavaScript gives us three keywords to create variables:

KeywordCan the value change?When to use
const❌ NoUse this by default
let✅ YesWhen the value will change
var✅ YesOld style, avoid it

Key Takeaways

  • A variable stores a value. Use const by default and let when the value will change.