JavaScript: String Escape Sequence

By Xah Lee. Date: . Last updated: .

Escape sequence are sequence of characters starting with backslash, inside a string, to represent certain unprintable characters [see ASCII Characters] such as \n for Line Feed to represent newline, or to represent Unicode characters.

console.log("a\nb");
// prints a and b each on its own line
// the \n is a escape sequence. It means newline

List of Escape Sequences

\b
BACKSPACE
\t
CHARACTER TABULATION
\n
LINE FEED
\v
LINE TABULATION
\f
FORM FEED
\r
CARRIAGE RETURN
\"
QUOTATION MARK
\'
APOSTROPHE
\\
REVERSE SOLIDUS

Backslash in front of other character quote the char literally:

console.log("\l\ov\e" === "love");

Backslash in front of literal newline means continue the line:

console.log(
"a\
b\
c" === "abc",
);

Some of the escape sequence character can be in string literal directly without escaping.

// \t (tab character) can be in string literally
console.log("\t" === "	");

Unicode Character Escape Sequence

JavaScript String

BUY
Ξ£JS
JavaScript in Depth

JavaScript in Depth

Basic Syntax

Value Types

Variable

String

Property

Object and Inheritance

Array

Function

Constructor/Class

Iterable 🌟

Misc