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.
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 two ways: let
and const
, each with its own characteristics:
In JavaScript, we frequently encounter situations in which a variable doesn't have a value. In such cases, the null
and undefined
types come into play.
Imagine you possess a flower jar (variable), but it's empty. There is no flower inside. This absence of content is what null
in JavaScript represents — an intentionally empty or non-existent value.
Suppose you have a label for a candy jar, but you don't actually have the jar. This is where undefined
comes in. It indicates that a variable has been declared, but doesn't yet hold any value.
Here's a code example to illustrate:
