MENU
Escape Notation
Several special characters can be included within strings by escaping them with \.
\0the NULL character
\'single quote
\"double quote
\\backslash
\nnew line
\rcarriage return
\vvertical tab
\ttab
\bbackspace
\fform feed
\uXXXXunicode codepoint
\u{X} ... \u{reset_code("c-14-0","javascript");reset_frame("f-14","Escape_Notation-ZgCW.html");X}unicode codepoint
\xXXthe Latin-1 character
Notice how the number of characters of a string can be obtained with the .length property. Notice also how [] is used to access individual characters of a string.
RESETRUNFULL
RESETRUNFULL
<!DOCTYPE html><html><body><script>
var a = "\\\uFFFF";
console.log(a[0]); // \
console.log(a.length); // 2
var b = "你好吗?";
console.log(b.length); // 4
var c = "\n\n\n X";
console.log(c.length); // 5 //var c = "\"; // SyntaxError
function capitalizeFirstLetter(string) {
return string[0].toUpperCase() + string.slice(1);
}
</script></body><html>
<a href="JavaScript%20is%20a%20superset%20of%20JSON">JavaScript is a superset of JSON</a>, as of ES10.
RESETRUNFULL
RESETRUNFULL
<!DOCTYPE html><html><body><script>
const paragraph_separator = "\u2028";const line_separator = "\u2029";let code = '"\u2028\u2029"'console.log(JSON.parse(code)); // evaluates to "\u2028\u2029" in all engineseval(code); // throws a SyntaxError in old engines
</script></body><html>