CodePath

Beginner Learning Path

Your Progress

40%

5 of 12 lessons completed · keep the streak going 🔥

Roadmap

Module 2

Variables & Data Types

Goals

    Lessons

    4

    short lessons

    Estimated Time

    45min

    Your Progress

    25%
    Lesson 2 of 4

    Lesson: Variables

    Code on a laptop screen

    A variable is a named container for a value. In JavaScript you create one with let or const, then reuse it anywhere in your program.

    Code Example

    let name = "Alex";
    let age = 20;
    console.log(name);
    console.log(age);

    When this runs, the console prints Alex and then 20. Key ideas to remember:

    • Declare once, assign freely with let.
    • Use const for values that shouldn’t change.
    • Names are case-sensitive and should describe the value.
    Exercise 2 of 4

    Task

    Declare a variable city with your city’s name and a variable year with the current year, then log both to the console.

    Your Code

    1
    2
    3
    4
    5
    6

    Feedback

    Submit your solution to get instant feedback.
    Done