String

The String type in JavaScript allows us to express sequences of characters. It is usually used to encapsulate words, sentences, lists, HTML, and many other forms of text-like content.

Strings are expressed by delimiting sequences of characters with either single quotes, double quotes, or backticks:

// Single quotes:const name = 'Titanic';// Double quotes:const type = "Ship";// Template literals (back-ticks):const report = `  RMS Titanic was a British passenger liner that sank  in the North Atlantic Ocean in 1912 after the ship  struck an iceberg during her maiden voyage.`;

Only backtick-delimited strings, known as template literals (or template strings), can occupy multiple lines. Single quote- or double quote-delimited strings can technically ...

Get Clean Code in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.