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.
Lessons in this chapter ยท Getting Started with JavaScript
- 1. What is JavaScript?
- 2. What are Programming Languages?
- 3. How to Instruct a Computer
- 4. Comment
- 5. Multiple-choice quiz
- 6. Data Types
- 7. Variable Declaration Keyword - var
- 8. Scope
- 9. Variable Declaration Keyword - let
- 10. Constant
- 11. Operators
- 12. Variable Assignment
- 13. Identifiers and Literals
- 14. Fill-in-the-blank quiz
An identifier is a name used to distinguish variables, functions, objects, etc.
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help