vibecodai logovibecodai
← All JavaScript lessons

JavaScript · Lesson 2 · 10 min

Variables — Storing Information

Use let and const to save text and numbers in named boxes.

You will learn

  • Create variables with let and const
  • Store strings and numbers
  • Print variables with console.log

A variable is like a labeled box that holds a value. You can look inside the box later or change what is inside (when using let).

let vs const

Use const when the value should not change — like your username. Use let when the value might change — like a score in a game. Text goes in quotes. Numbers do not.

Try it

Create a variable for your name and one for your age. Print both on separate lines.

Try it yourself

Output

Press Run code to see results here.

Tip: Add a third variable for your favorite color and log it.