JavaScript: String Escape Sequence

By Xah Lee. Date: . Last updated: .

The following are escape sequences:

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

Example:

console.log( 
"a\nb" === `a
b`);
// true

[see Template String]

Backslash in front of other character usually has no special meaning:

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

Backslash in front of literal newline means continue the line:

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

// true

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" === "      "
); // true

Characters Not Allowed in String Literal

The following are not allowed in string literal. They must be escaped.

if you include them without escape, you get syntax error.

console.log( 
"a
b"
);
// SyntaxError: Invalid or unexpected token

Unicode Character Escape Sequence

Unicode Escape Sequence

JavaScript String

βˆ‘ JS in Depth
XAH Β BUY NOW

JS in Depth

JS Obj Ref

DOM


JS in Depth

Basic Syntax

Value Types

Variable

String

Function

Property

Object and Inheritance

Array

Constructor/Class

Iterable 🌟

Misc