Need help in "Escape Sequences in Strings"

Need help in "Escape Sequences in Strings"
0

#1

Hey, I want to get help on this chapter,
I tried lots of other ways but nothing works, I need help escaping the sequences…

Here’s my code
var myStr = "FirstLine'\n'\\\\SecondLine\\\\'\n'ThirdLine"; // Change this line

Thanks.


#2

You don’t need single quotes around \n


#3

Here are some rules for using escape sequences that may help you out in the future:

  • If the string iis surrounded in double quotes, you don’t need to escape single quotes.

  • If the string is surrounded in single quotes you don’t need to escape double quotes.

  • Escape sequences can be used for other characters as well such as tabs (\t);

When using escape sequences I like to think of the backslash as a ladder that the next character can use to climb out of the string.,

Hope this helps.


#4

I might be late to this but here is the answer:
var myStr= “FirstLine\n\SecondLine\\rThirdLine”;