Variables: Boxes With Labels

Teach your program to remember things. Nine short pages from Grade 1 of Elementary School, about 14 minutes of reading in all.

What you’ll learn

  • What a variable is
  • How to create variables with let
  • Locking values with const
  • Why we (mostly) avoid var
  • The rules for naming variables
  • What undefined means
  • How to update variables using their old value
  • Your first mini project: a receipt

The pages

Nine pages, about 14 minutes.

  1. What Is a Variable? Imagine you're moving to a new house. You've got a whole pile of stuff to pack, so you grab some cardboard boxes. You…
  2. Creating Variables with let Here's how you create a variable in JavaScript. Let's take this apart, piece by piece. So let age = 25; reads like…
  3. const: Boxes With Locks Sometimes you have a value that should never change. The number of days in a week. The value of pi. Your birthday. For…
  4. var: Grandpa's Old Box If you look at older JavaScript code online (anything written before about 2015), you'll see variables created with a…
  5. Naming Your Variables Naming things is one of the trickiest parts of programming. There's an old programmer joke. "There are only two hard…
  6. Declaring, Assigning, and undefined Here's something interesting. You don't have to put a value into a let box right away. You can create an empty box now…
  7. Variables Working Together Variables become really useful when you start combining them. JavaScript looks inside the boxes, finds 45 and 3…
  8. Mini Project: The Café Receipt Time to put it all together! Let's write a program that prints a receipt for a meal at a café. Look at that! A real…
  9. Recap The key ideas of Grade 1, JavaScript variables, on one page. A variable is a named box that holds a value. Create…

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning