Literal is a data value that is used directly in a JavaScript code.
Here are some examples:
34
"Backbencher.dev"
null
Based on the type of data value, the literals can be classified as:
Literals that are of type number are called number literals.
Here are some examples:
23
45.12
-12
Literals that are of type string are called string literals.
Here are some examples:
""
"Backbencher"
There are only two boolean literals. They are true
and false
.
null
is a literal that is of null
type.
undefined
is a literal that is of undefined
type.
Literals that are of Array type are called Array literals.
Here are some examples:
[]
[2, 4, 7]
Data values that are of Object type are called Object literals.
Here are two examples:
{}
{
name: "Backbencher",
age: 3
}