So this is what i have var myStr = ‘I am a “double quoted” string inside “double quotes”.’;
And it wants me to You should use two double quotes ( " ) and four escaped double quotes ( \" ).
Variable myStr should contain the string: I am a "double quoted" string inside "double quotes". please help
In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash ( `\` ) in front of the quote.
`var sampleStr = "Alan said, \"Peter is learning JavaScript\".";`
You seem not to be using any backslashes anywhere in your code.
Your string is inside single quotes (') not double quotes ("). You will need to escape your double quotes inside the string with the escape charcter (\).
A string is a data type in JavaScript. it is commonly wrapped around by either a single(’ ') or double (" ") quotation mark.
Assuming you have a variable which stores a string,
let variable='this is a string'
the computer will understand that it is just a string.
But if you want to quote something in the string above,
let variable='this "is" a string'
This will be confusing to the computer because it interpretes anything wrapped around by single or double quotation as a string. therefore, it will be seeing a string “is” inside another string which is not reasonable to it.
So to make the computer to understand that “is” is not a string, you have to place a backslash () before any quotation mark in a string. the variable above is written correctly as:
var variable='this \"is\" a string'
The computer will read this as:
this “is” a string
Notice the backslash coming before every quotation mark you dont want the computer to consider as a string.