Lesson Introduction

Hello, and welcome to your JavaScript journey! Today's quest is to understand variables — our way of storing data, much like jars for keeping cookies. We'll see how to create these jars with labels (let and const), what to write on these labels (naming variables), how to fill them (assigning values), and then how to display our cookies (printing values). Let's dive in and start our delicious coding adventure!

What is a Variable?

In JavaScript, variables are the tags we create to track and use our data.

  • For changeable data, such as the number of cookies in your jar, which is likely to change, we use let.
    • It’s like having a grocery bag that we can fill and empty often.
  • For unchanging values, const is the go-to choice.
    • Imagine a piggy bank for a specific type of coin; once it’s in there, it’s intended to stay.

Here is an example:

By the end of this lesson, you'll understand how to declare variables for dynamic and static values.

Naming Variables

Variables should be clearly named to indicate the data they contain. Good naming is like a well-labeled spice rack: it allows you to find exactly what you need at a glance. Start variable names with letters, underscores (), or dollar signs (), and avoid reserved words like , , and similar.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal