So, here is the thing.
When I try the same code on my JS console (using Safari) the double backslash will actually return two backslashes instead of one escaped backslash. Anyone know why this happens?
const myStr = "FirstLine\n\t\\SecondLine\nThirdLine";
Your browser information:
User Agent is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15
Challenge: Escape Sequences in Strings
Link to the challenge:
It’s printing the literal representation, as in the actual contents of the string, though this console (confusingly) in this implementation happens to treat \n and \t as literal new lines and tabs.
ie you have written a string which has two backslashes, so it’s printing a string that’s got two backslashes. Afaik, if that’s Chrome, it did used to escape the string rather than printing the literal representation, but that seems to have been “fixed”
Edit: you can see the difference if you use console.log on it:
Oh, I get it now! Thanks @DanCouper!
Thanks, even I didn’t knew this.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.