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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.