JS: Quote String

By Xah Lee. Date: . Last updated: .

"QUOTATION MARK" Delimited String

Use QUOTATION MARK delimiter to enclose string.

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

Use \" to embed a QUOTATION MARK.

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

Literal Newline Not Allowed

// illegal syntax. 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 sequence)

Backslash at end of line continues the line without linebreak

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