freeCodeCamp Challenge Guide: Quoting Strings with Single Quotes

Quoting Strings with Single Quotes


Problem Explanation

String values in JavaScript may be written with single or double quotes, so long as you start and end with the same type of quote. Unlike some languages, single and double quotes are functionally identical in JavaScript.

"This string has \"double quotes\" in it"

The value in using one or the other has to do with the need to escape quotes of the same type. If you have a string with many double quotes, this can be difficult to read and write. Instead, use single quotes:

'This string has "double quotes" in it. And "probably" lots of them.'

Solutions

Solution 1 (Click to Show/Hide)
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
19 Likes

but this is way different from it this one is asking about to correct the website

4 Likes

I’m not sure you’re able to complete the challenge as is.

Example:
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";

Correct Solution:
var myStr = "<a href='http://www.example.com' target='_blank'>Link</a>";

This condition is not fulfillable:

You should have two single quotes ’ and four double quotes "

7 Likes

it still didn’t work I just got the first one right

3 Likes

var myStr = “Link”;
This is not working for me :frowning:

2 Likes

var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';

This is my code. And it is correct.

53 Likes

Thanks, that clarified my general misunderstanding with that section.

2 Likes

thank you it worked.

1 Like