Js carriage return and backslahes aren't making sense a bit

I keep seeing things about this “carriage return”, and I have gone through this js list of tutorials one by one and never learned what the heck this means. I can surely look it up, but I was under the impression I would be taught anything of context throughout. Turns out my code was very similar to correct solution and I just ignored that carriage return since I have no idea what it does, I am not sure why other people are including it in their solutions when we haven’t explicitly learned about it. I can interpret what \n does of course.
This was my code

var myStr = "FirstLine\n\t\SecondLine\nThirdLine"; // Change this line

I saw in the solution to put one backslash before the backslash that actually shows up in the solution in front of second line. How does this second backslash allow the other one to stay?

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Link to the challenge:

Carriage return is this key in your keyboard:

It isn’t taught because it’s just a thing that you use when you input text on a computer. In a string it needs a special escape character because you aren’t using a keyboard, you’re writing a string.

lol oh, I am sorry, maybe I should have just known that. I knew it was ‘return’ but I didn’t know what carriage return meant. Okay thank you!

1 Like

I guess it’s falling out of fashion, calling it that isn’t that common now – normally just called “return”, so not that strange. It comes from typewriters (the carriage is the mechanism that’s the top part of the typewriter). A carriage return is a metal bar that moves the carriage back to the start of the line on the piece of paper, then line feed moves the paper up so you can start typing on the next line.

As an aside. Minor thing but kinda important in programming because it changes how text files are saved: Microsoft systems in particular generally use carriage return command then line feed command, Unix systems generally just use a newline command. Text editors now often automatically set the right thing based on what system you’re using, but it still occasionally causes issues

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

okay, noted, thank you very much!

oh interesting. I probably won’t use Unix often so I will remember that difference. Very good information, thank you!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.