i want to write this sentence in 3 lines but on scrimba this does not work but on Repl.lt (https://repl.it/repls/WickedBaggyRegression) it works, why?

var myStr = 'FirstLine\n\\SecondLine\\\rThirdLine';
console.log(myStr);

2 Answers

0
Himanshu Singh On Best Solutions

If you open up the browser console, you can see that the escape characters work perfectly fine. Please don't rely on the inbuilt console of tutorial sites, for the credibility of Javascript.

enter image description here

1
el-teedee On

It is probably due to how scrimba.com site does interpret and displays your log in its own custom console.
(it probably wrap the text console.log receives in a single line.)

Try by replacing console.log by alert and you will see escape sequences are "preserved" in the alert popup displayed in the simulated browser, which means, they are correct in a JavaScript way :

I also found a course that explain this: https://scrimba.com/p/p4Mrt9/c4vJdha

enter image description here