Escaping Literal

Escaping Literal
0.0 0

#1

Tell us what’s happening:
where should I put the backslash unable to understand
anyone please assist me.

Your code so far


var myStr = "I am a "double quoted" string inside "double quotes"."; // Change this line


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings


#2

Think about how you define a string in JS: you wrap it in quotation marks.

So in the above, JS is going to read that code as

// start of string
"I am a "
// end of string

// syntax error, string has ended
double quoted
// and if JS could continue:

// start of another string
" string inside "
// end of string

// syntax error
double quotes

// start of string
"."
// end of string

JS can’t tell that the double quote marks inside the string are meant to be actual quotation marks rather than start/end of strings unless you tell it that by escaping them.

At the minute, to the the JS parser, it looks like there are three strings with some gibberish inbetween.


#3
var myString = " every double quote after the \"FIRST QUOTE\" will need a \\ to escape it except the \"LAST QUOTE\" ";

console.log(myString);

copy the above code to the developer console to see the charterers ESCAPED


#4

Thanks guys finally got it