almost 5 years ago

## The new line character

Two special characters are involved here:

• Carriage Return (CR or \r in many programming languages)
• Line Feed (LR or \n)

I never understood what those terms mean until I read that they are inherited from typewriters. When typing on a type writer, two physical actions have to happen in order to continue typing on the next line. First, the carriage needs to return to the very beginning (the far left and makes the ding sound). Then, the typewriter needs to move the page up a little so that we can type on a new line. The moving page up action is called line feed.

Windows uses CR+LR (i.e. \r\n) to denote a new line but on Unix and Unix-like machines (e.g. Linux), only LF or \n is used.

Some interesting behaviour of how CRLF is treated in JavaScript [*]:

JavaScript and XPath treat CRLF pairs as two line breaks. ^ matches in the middle of and after CRLF, while \$ matches before and in the middle of CRLF.