How to use string literal In Javascript

A string can be created just by initializing with a string literal. There are three ways to write a string literal:

  • inside single quotes(‘ ‘)
  • inside double quotes(” “)
  • inside template literals or backticks(` `)

Example:

Javascript




let singleQuotes = 'string created with single quotes.';
let doubleQuotes = "string created with double quotes.";
let templateLiteral = `string created with template literals.`;
console.log(singleQuotes);
console.log(doubleQuotes);
console.log(templateLiteral);


Output

string created with single quotes.
string created with double quotes.
string created with template literals.

String in JavaScript

String is used to representing the sequence of characters. They are made up of a list of characters, which is essentially just an “array of characters”. It can hold the data and manipulate the data which can be represented in the text form. We can perform different operations on strings like checking their length, also concatenate them by using +=, +, string operators.

Similar Reads

Creating Strings:

There are two ways to create a string in Javascript:...

Method 1: Using string literal

A string can be created just by initializing with a string literal. There are three ways to write a string literal:...

Method 2: Using string object

...

Character Access:

A string can also be created using a String object....

Method 1: Using charAt() Method

...

Method 2: String as an array-like object

A character can be accessed from a string in one of two ways....

Contact Us