Introduction and Overview

Let's explore JavaScript variables — the essential containers for storing data — along with assignment and equality operators, which facilitate our interaction with these variables. After this lesson, you'll understand how to define, use variables, and comprehend the operators.

Understanding Variables

Think of a variable in JavaScript as a box. This box stores data that can be changed, accessed, and manipulated within a program. Variables are declared in three ways: let, var and const, each with its own characteristics:

Why We avoid using var

You might encounter var in older JavaScript code or tutorials, and it's important to understand why modern JavaScript favors let and const instead.

The Problem with var:

var has quirky scoping rules that can lead to unexpected bugs. It uses "function scope" instead of "block scope," meaning variables declared with are accessible throughout the entire function, even outside the blocks where they're declared:

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