JavaScript

Lesson 2 of 11

Lesson ยท 8 min

Variables

Names for values

A variable is a name that points to a value. You create one with const or let.

const city = 'Lisbon';
let temperature = 18;
console.log(city);
console.log(temperature);

Use const for a value that will not change. Use let for a value that will change. If you try to change a const, JavaScript stops with an error.

let score = 10;
score = 12; // allowed: score was made with let

Template strings

A template string uses backticks instead of quotation marks. It lets you put a value inside the text with ${ }.

const name = 'Sam';
console.log(`Hello, ${name}!`);

The backtick key is usually at the top left of the keyboard, below the Esc key.

Your turn

Follow the three tasks. Each task is checked on its own.

Tasks

3 to do

  1. Task 1, not checked yet. Make a constant named planet with the text Mars.

  2. Task 2, not checked yet. Make a variable named visitors with the number 3. On the next line, change it to 4.

  3. Task 3, not checked yet. Print the sentence Mars has 4 visitors today. Build it with a template string that uses planet and visitors.

Task 1 of 3

Make a constant named planet with the text Mars.

All tasks

main.js

Ctrl+Enter runs your code. Ctrl+Shift+Enter checks it. Press Esc, then Tab, to leave the editor.

Output

Press Run to see your result

Your output shows here. Press Run to try your code.