Variables and printing

What a program and a variable are; store values and print them.

1. What is this?

A program is instructions the computer runs top to bottom. A variable is a named box that holds a value so you can reuse it. With let name = "Ava" you create a box called name holding the text Ava. console.log(...) prints a value to the output so you can see it.

2. Why do we use it?

Every app stores things: usernames, totals, settings. Variables are that storage. Logging is how you check what your program is doing.

3. Syntax breakdown

  • let name = "Ava";

    let creates a variable. name is its label. = stores the value "Ava" in it.

  • let age = 28;

    Numbers need no quotes. Text (strings) does.

  • console.log(name);

    Prints the value of name to the output panel.

5. Common mistakes

  • Forgetting quotes around text: let name = Ava looks for a variable called Ava.
  • Using = (store) when you mean === (compare) — covered in the next module.
  • console.log(name) after misspelling the variable (Name vs name — case matters).

Practice task

Create a variable city with your city, and log "I live in <city>."

Hint

let city = "..."; then console.log("I live in " + city + ".");

Try it below — tests run automatically when you press Run.

javascript

Output

Press Run to see output.

Mini quiz

3 questions. Answer, then check.

  1. 1. What is a variable?

  2. 2. Which line creates a text variable correctly?

  3. 3. What does console.log do?

4. Example — edit and run

javascript

Output

Press Run to see output.

Expected output: Hello, Ava