# Escape Sequences in Strings

**URL:** <https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116>\
**Category:** General\
**Created:** [August 11, 2016, 4:06am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116 "2016-08-11T04:06:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mangalita](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@mangalita](https://forum.freecodecamp.org/u/mangalita)\
**Post date:** [August 11, 2016, 4:06am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/1 "2016-08-11T04:06:49Z")

</div>

This what is required  
Here is the text with the escape sequences written out.

FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine

Run tests (ctrl + enter)  
Reset Help Bug

SyntaxError: Invalid or unexpected token

myStr should have encoded text with the proper escape sequences and no spacing.  
myStr should have one newline character \n  
myStr should have one carriage return character \r  
myStr should have two correctly escaped backslash characters \  
below is my change to the original code  
var myStr = FirstLine\n /SecondLine/r ThirdLine\;

---

<div class="post-metadata">

**Author:** ![mangalita](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@mangalita](https://forum.freecodecamp.org/u/mangalita)\
**Post date:** [August 12, 2016, 1:03am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/3 "2016-08-12T01:03:24Z")

</div>

var myStr=Firstline\Seconfline\rThirdLine\;  
This my new answer but its wrong  
See below what they want me to do  
myStr should have encoded text with the proper escape sequences and no spacing.  
myStr should have one newline character \n  
myStr should have one carriage return character \r  
myStr should have two correctly escaped backslash characters \

---

<div class="post-metadata">

**Author:** ![ferhotguy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ferhotguy/32/13818_2.png) [@ferhotguy](https://forum.freecodecamp.org/u/ferhotguy)\
**Post date:** [August 17, 2016, 12:34pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/4 "2016-08-17T12:34:35Z")

</div>

Yes it is annoying , coding really deserving attention in small detail

var myStr=“FirstLine\n\SecondLine\\rThirdLine”;

this is the correct answer, there will be 2 backslashes before and will be 3 backslashes after SecondLine

---

<div class="post-metadata">

**Author:** ![lcwallet](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lcwallet/32/165293_2.png) [@lcwallet](https://forum.freecodecamp.org/u/lcwallet)\
**Post date:** [August 18, 2016, 3:00am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/5 "2016-08-18T03:00:05Z")

</div>

> [@ferhotguy](#):
>
> var myStr=“FirstLine\n\SecondLine\rThirdLine”;
> 
> this is the correct answer, there will be 2 backslashes before and will be 3 backslashes after SecondLine

The right answer should be :  
var myStr=“FirstLine\n\\SecondLine\\\rThirdLine”;

The backslash should be \\ instead of \

I guess ferhotguy got it right, but there’s issue with code editor here

cheers

---

<div class="post-metadata">

**Author:** ![nigelFrancisNET](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nigelfrancisnet/32/158888_2.png) [@nigelFrancisNET](https://forum.freecodecamp.org/u/nigelFrancisNET)\
**Post date:** [September 23, 2016, 2:27pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/7 "2016-09-23T14:27:11Z")

</div>

WOW … seriously, what the heck is that about? 😱

var myStr = “FirstLine\n\SecondLine\\rThirdLine”;

Eventually I got it to except my answer. But what it really means is another thing!

---

<div class="post-metadata">

**Author:** ![ajitkumarsahu](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ajitkumarsahu/32/26669_2.png) [@ajitkumarsahu](https://forum.freecodecamp.org/u/ajitkumarsahu)\
**Post date:** [December 10, 2016, 3:16pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/8 "2016-12-10T15:16:22Z")

</div>

it is not working the first condition is not yet becoming successful

---

<div class="post-metadata">

**Author:** ![the-thief](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/the-thief/32/27876_2.png) [@the-thief](https://forum.freecodecamp.org/u/the-thief)\
**Post date:** [December 11, 2016, 2:02am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/9 "2016-12-11T02:02:11Z")

</div>

Can you post your code here?

---

<div class="post-metadata">

**Author:** ![iamnumber2407](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/iamnumber2407/32/37900_2.png) [@iamnumber2407](https://forum.freecodecamp.org/u/iamnumber2407)\
**Post date:** [February 3, 2017, 2:45pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/10 "2017-02-03T14:45:12Z")

</div>

was able to pass the challenge using this:

`var myStr="FirstLine\n\\SecondLine\\\rThirdLine";`

---

<div class="post-metadata">

**Author:** ![Woodshadow](https://avatars.discourse-cdn.com/v4/letter/w/c5a1d2/32.png) [@Woodshadow](https://forum.freecodecamp.org/u/Woodshadow)\
**Post date:** [February 19, 2017, 12:27am UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/11 "2017-02-19T00:27:41Z")

</div>

I used your code but the output doesn’t match what it says the output should be. I can’t help but feel like something is wrong.

---

<div class="post-metadata">

**Author:** ![tanviranwar](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/tanviranwar/32/163334_2.png) [@tanviranwar](https://forum.freecodecamp.org/u/tanviranwar)\
**Post date:** [February 27, 2017, 2:39pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/12 "2017-02-27T14:39:43Z")

</div>

yep bro, this is the right ans.

---

<div class="post-metadata">

**Author:** ![bzouzou](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bzouzou/32/48641_2.png) [@bzouzou](https://forum.freecodecamp.org/u/bzouzou)\
**Post date:** [March 28, 2017, 4:12pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/14 "2017-03-28T16:12:42Z")

</div>

the mistake is the “;” in the initial code instead of = sign

```auto
var myStr; // Change this line

```

the correct answer is 🙂

```auto

var myStr= "FirstLine\n\\SecondLine\\\rThirdLine";

```

---

<div class="post-metadata">

**Author:** ![Soupedenuit](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/soupedenuit/32/32478_2.png) [@Soupedenuit](https://forum.freecodecamp.org/u/Soupedenuit)\
**Post date:** [March 28, 2017, 4:38pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/15 "2017-03-28T16:38:10Z")

</div>

Side note, if some of you use [Repl.it](https://repl.it/languages/javascript), carriage return and newline don’t work as expected. Otherwise it’s a pretty great tool.

---

<div class="post-metadata">

**Author:** ![lightokira](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@lightokira](https://forum.freecodecamp.org/u/lightokira)\
**Post date:** [April 20, 2017, 6:51pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/16 "2017-04-20T18:51:11Z")

</div>

var myStr = “FirstLine\n\\SecondLine\\rThirdLine”;  
note: see for capital letter when typing.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:08pm UTC](https://forum.freecodecamp.org/t/escape-sequences-in-strings/27116/17 "2021-01-16T13:08:20Z")

</div>

Closed on January 16, 2021, 1:08pm UTC


