Course overviewRepresentative launch lessonPractice

JAVASCRIPT FOUNDATIONS

Store values with variables

Variables give names to values. Good variable names make programs easier to read, update, and debug.

What you will learn

  • Declare values with const and let
  • Choose the right declaration for a value
  • Use clear names that explain intent

The concept

A variable connects a name to a value. Use const by default. Use let only when your program needs to assign a new value later.

Practical rule

Start with const. Change it to let only when reassignment is intentional.

Run this code

Change the role or starting count, then run the example in an isolated browser worker.

main.js
OUTPUTReady
Frontend Developer: 3

How it works

  1. 1

    role never receives a different value, so it uses const.

  2. 2

    applications increases, so it uses let.

  3. 3

    The template string combines both values into readable output.

Common mistake

Reassigning a constant

const score = 1; score = 2; throws an error. Use let when reassignment is required.

Exercise

YOUR TURN

Track completed lessons

Create a variable named completedLessons, increase it by one, and print the result.

Open exercise

Interview connection

Be ready to explain scope, reassignment, and why const does not make an object deeply immutable.