Variables in JavaScript

A variable is a named box where you can store a value so you can use it later.

How to create a variable

Use const when the value should not change, and let when it will.

Can edit

Output

No output yet. Click Run.

Why it matters

Variables let you reuse values without typing them over and over. You can also update them as your program runs.

Try it yourself

Open your browser console and run:

Read-only

Summary

  • A variable stores a value under a name.
  • Use const by default.
  • Use let when you need to change the value later.