The variable is a fundamental concept that any developer should know.
In JavaScript, const
, let
, and var
are the statements you can declarate variable.
I’m going to describe each variable type around the declaration, initialization, value access, and assignment. Each of the 3 types (const
, let
, and var
) create variables that behave differently exactly in these 4 steps.
This post isn’t quite beginner friendly, but rather useful to solidify your knowledge of variables and their behavior.
Let’s get started.
First, let’s understand what a variable is.
In simple terms, a variable is a placeholder (or a box) for a value. A value in JavaScript can be either a primitive value or an object.
The variable has a name, which stricter is called identifier. Examples of identifiers are myNumber
, name
, list
, item
.
The syntax of an identifier is pretty simple:
An identifier can contain letters, digits
0..9
, and special symbols$
,_
. An identifier cannot start with a digit0..9
.
Examples of valid identifiers are myNumber
, my_number
, list1
, $item
, _name
, a
, b
, $
, _
.
#javascript #variable #const #let #var