Tell us what’s happening:
Describe your issue in detail here.
Your code so far
const myStr =
"FirstLine\n\t \\SecondLine\nThirdLine"; // Change this line
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 11; Infinix X688B Build/RP1A.200720.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/97.0.4692.98 Mobile Safari/537.36
Challenge: Basic JavaScript - Escape Sequences in Strings
Hi, in the string:
“FirstLine\n\t \SecondLine\nThirdLine”
The back-slashes have the following function:
\n : This will be “substituted” with a “newLine-character”
\t : This will be “substituted” with a “tab-character”
\ : This will be substituted with a single "" character.
Just to complement by answer above.
I can of course not with certainty say what the “purpose is”. But the only “real difference” that the “space character” does, is that it “indents” the second row 1 “space character” further (i.e. the full indent is 1"tab"+1"space". Instead of just 1"tab"…
So with the original string it would “print”:
FirstLine
\SecondLine
ThirdLine
But if You take away the “space character”, so the string would be:
“FirstLine\n\t\SecondLine\nThirdLine”;
It would “print”:
FirstLine
\SecondLine
ThirdLine
Do You see the difference ?.. It’s hardly visible, and I really can not speak to it’s purpose.
Best regards.