Quote a String

The 3 Ways to Quote a String

Quotation Mark Quote

Use quotation marks to enclose a quote

"my cat"

Use \" to embed a quotation mark

console.log("my \"3\" cat" === `my "3" cat`);

Apostrophe Quote

Use \' to embed a APOSTROPHE.

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

	// now by escaping...
	console.log('john\'s cat');
	// john's cat

Difference Between APOSTROPHE and QUOTATION MARK Quoted String

There's basically no difference, except that if you need to embed a APOSTROPHE or QUOTATION MARK , you need to escape it.

Literal Newline in QUOTATION MARK or APOSTROPHE Quoted String Not Allowed

Use backslash to continue a line.

	illegal syntax. Literal newline is not allowed

	let xx = "a
	b";

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

Characters Not Allowed

The following are not allowed

If you include them without escaping you get a syntax error

Use Backslash to Continue a Line

	let xx = "c\
	d";

	console.log(xx === "cd");

String Escape Sequence

Use \n for newline

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