2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Escaping Literal Quotes in Strings
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Escaping Literal Quotes in Strings
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
* When you need to use a special character such as `"` inside a string you need to escape it using `\`.
|
|
|
|
* If you use double quotes `"` for the string, single quotes `'` in the string do not need to be escaped.
|
|
|
|
* If you use single quotes `'` for the string, double quotes `"` in the string do not need to be escaped.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
2019-07-24 00:59:27 -07:00
|
|
|
var myStr = 'I am a "double quoted" string inside "double quotes".';
|
|
|
|
var otherStr = "I am a 'single quoted' string inside 'single quotes'.";
|
2018-10-12 15:37:13 -04:00
|
|
|
var noEscapeSingle = "There is no need to 'escape' the single quotes.";
|
|
|
|
var noEscapeDouble = 'There is no need to "escape" the double quotes.';
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|