Backbencher.dev

Literals

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:

  1. Number literal
  2. String literal
  3. Boolean literal
  4. null literal
  5. undefined literal
  6. Array literal
  7. Object literal

Number Literal

Literals that are of type number are called number literals.

Here are some examples:

23
45.12
-12

String Literal

Literals that are of type string are called string literals.

Here are some examples:

""
"Backbencher"

Boolean literal

There are only two boolean literals. They are true and false.

null and undefined literals

null is a literal that is of null type.

undefined is a literal that is of undefined type.

Array Literal

Literals that are of Array type are called Array literals.

Here are some examples:

[]
[2, 4, 7]

Object Literal

Data values that are of Object type are called Object literals.

Here are two examples:

{}

{
    name: "Backbencher",
    age: 3
}
Last updated on 23 Sep, 2022
Joby Joseph
Web Architect