3. Strings

The Web is made up of text: HTTP is a text-based protocol, and browsers consume Web content in HTML text files. JavaScript handles text in a flexible, capable manner with the powerful String data type.

Escape Characters

You can surround characters with either single primes (′) or double primes (″) to create a string. But whichever symbol you use, you can’t use it again in the middle of the string because that will end the string early. However, you can escape any character with a backslash (\) to solve this or use single primes inside double primes (and vice versa).

image

Escape sequences are useful for other things too, such as for newlines ...

Get The JavaScript PocketGuide 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.