Identifiers and Literals
Identifiers
and Literals
are essential and universal concepts used in programming.
Let's explore what identifiers and literals are, and how they are used.
Identifiers
An identifier is a name used to distinguish variables, functions, objects, and more.
For example, in let appleCount = 5;
, appleCount
is an identifier.
Rules for Identifiers in JavaScript
Identifiers can start with a letter, a dollar sign ($
), or an underscore (_
).
From the second character onward, numbers can also be included, and keywords like let
and const
cannot be used as identifiers.
Literals
A literal is a fixed value directly embedded in the source code.
Literals are used "as is" when assigned to variables or used in operations.
For example, in let appleCount = 5;
, 5
is a literal.
Types of Literals
-
Numeric literals:
123
,3.14
-
String literals:
"hello"
,'world'
-
Boolean literals:
true
,false
-
Object literals:
{name: "John", age: 30}
-
Array literals:
[1, 2, 3]
-
Regular expression literals:
/ab+c/
In brief, an identifier is a name for referencing or invoking data or functions, while a literal is a fixed value directly used in the code.
An identifier is a name used to distinguish variables, functions, objects, etc.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help
Code Editor
Execution Result