JS: Quote String

By Xah Lee. Date: . Last updated: .

Quotation mark quoted string

String can be created by bracketing text with "U+22: QUOTATION MARK".

Use \" to embed a QUOTATION MARK.

console.log("my cat");
// my cat

console.log("he said \"yes\"");
// he said "yes"

Literal Newline Not Allowed

// Literal newline is not allowed

/*
let xx = "a
b";
*/

// error: The module's source code could not be parsed

Include newline

Use \n for newline.

console.log("cat\ndog");
/*
cat
dog
*/

String Escape Sequence

Backslash at end of line

// Backslash at end of line continues the line without linebreak
let xx = "a\
b";
console.log(xx);
// ab