JavaScript Removing the Escape Character

Deep Space
Jan 5, 2022

In JavaScript you can use both single and double quotes to create a string.

In the previous article we talked about the Escape Character .

In JavaScript strings, may be written with single or double quotes, as long as you start and end with the same type of quote.

Instead of using double quotes inside double quotes, and then
escape the literal quote with \ (backslash) like this:

const myStr = "Sir Isaac Newton \" Discovered Gravity\" ";
console.log(myStr);

We can wrap the whole string with single quote, and then use double quotes for the literal quote.

like so:

const myStr = 'Sir Isaac Newton "Discovered Gravity". ';console.log(myStr);

So in the code above when we started/wrapped the whole string with single quote. We didn’t have to escape anything to get a literal quote.

--

--

Deep Space

I’m Lia Sue Kim, a Math Lover. Obsessed with Computer Programming, Design and Science. Learn Web Development at https://w7school.com