Difference between \r and \n

\r is “Carriage Return” (CR, ASCII character 13), \n is “Line Feed” (LF, ASCII character 10). Back in the days, you had two ASCII characters at the end of each line to tell a printer what to do – CR would tell the printer to go back to the left edge of the paper, LF would advance to the next line.

Operating systems still have different conventions as to what the end of a line looks like — some of them have \n\r, some have \n, some have \r\n.

In Javascript, you mostly deal with \n – this is how strings are typically switching to the next line. However, depending on what strings you are working with, you may be encountering \r as well.

Leave a Comment