-3

var myStr = 'This string has "double quotes" in it. And "probably" lots of them';

The value in using one or the other has to do with the need to escape quotes of the same type. Unless they are escaped, you cannot have more than one pair of whichever quote type begins a string.?? //what does it mean??

//Error i got:- Remove all the backslashes () You should have two single quotes ' and four double quotes " Only remove the backslashes \ used to escape quotes.

can anyone tell what should i do to make it correct?

2 Answers2

0

It means that while using single quotes or double quotes do the same thing, if you try to wrap your entire string in single quotes, you won't be able to use single quotes in middle of your string without using \

What the backslash does is called "escaping", which tells javascript that you want to use that quotation mark as part of the string, and not to mark the beginning or end of a string

0

You have to use either single quotes or double quotes for the outermost quotes to for the string. Inside the string you can use the other type of quote or escape the quote.

var myStr1 = 'This string has "double quotes" in it. And "probably" lots of them';    //Works!
var myStr2 = 'This string has \'double quotes\' in it. And "probably" lots of them';    //Works!
var myStr3 = 'This string has 'double quotes' in it. And "probably" lots of them';    //Doesn't work
Jay Buckman
  • 581
  • 5
  • 18