JS: String Escape Sequence
What is Escape Sequence
Escape sequence
are sequence of characters starting with backslash, inside a string,
to represent certain unprintable 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
-
\"
- QUOTATION MARK
-
\'
- APOSTROPHE
-
\\
- REVERSE SOLIDUS
-
\b
- BACKSPACE γsee ASCII Charactersγ
-
\f
- FORM FEED
-
\n
- LINE FEED
-
\r
- CARRIAGE RETURN
-
\t
- CHARACTER TABULATION
\uβ¦
- Unicode Escape Sequence
-
\v
- LINE TABULATION
Backslash
Backslash in front of other character quote the char literally:
"\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" === " ");
JavaScript, String
- JS: String Overview
- JS: Quote String
- JS: Template String
- JS: String Escape Sequence
- JS: Unicode Escape Sequence
- JS: String Operations
- JS: Iterate String
- JS: String Code Unit
- JS: Count Chars in String π
- JS: Tagged Template String
- JS: Regex Functions
- JS: Convert String, Number
- JS: String Object
- JS: String Constructor
- JS: String.prototype