JavaScript Literals

JavaScript literal represents a data value in a program. Literals are often used to initialize variables. A JavaScript literal can be an array, boolean, floating-point, string value or even an Object.

For example, in the following case, “Kevin” is a string literal and 100 is a number literal.

let firstName = “Kevin”;
let num = 100;

In other words any value is a literal. If you write a string “Hello World”, it is a literal or any number like 100 or Boolean value true or false is also literal.

Following are all literals.

20  //Number literal
10.5 //Floating-point literal
“Welcome” //String literal
“This is text” //String literal
true  //Boolean literal