Escape Sequences

Download javascript eBook


Not everything that starts with a backslash is an escape sequence. Many characters are just not useful to escape sequences, and will simply cause a preceding backslash to be ignored.

"\H\e\l\l\o" === "Hello" // true

On the other hand, some characters like "u" and "x" will cause a syntax error when used improperly after a backslash. The following is not a valid string literal because it contains the Unicode escape sequence prefix \u followed by a character that is not a valid hexadecimal digit nor a curly brace:

"C:\Windows\System32\updatehandlers.dll" // SyntaxError

A backslash at the end of a line inside a string does not introduce an escape sequence, but indicates line continuation, i.e.

uation" === "continuation" // true

Similarity to other formats

While escape sequences in JavaScript bear resemblance to other languages and formats, like C++, Java, JSON, etc. there will often be critical differences in the details. When in doubt, be sure to test that your code behaves as expected, and consider checking the language specification.

Related Examples


550 Contributors: 1
Saturday, August 13, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial:

Download eBook