\n vs \r - waht's the difference?

I am in the Basic JavaScript: Escape Sequences in Strings Challenge at the moment and don’t quite get the difference between \n (new line) and \r (carriage return).

Can anyone shed some light on this?

\r - Carriage Return
\n - Line Feed

\r\n is often used in preference to \n as it displays properly on both unix and Windows.

Carriage Return ( \r ) just returns the cursor to the beginning of the same line (without advancing to the next line) whereas a Line Feed ( \n ) feeds a new line.

2 Likes

thx for the feedback

ok, I am then just wondering …

if a line feed (\n) creates a new line by itself. What is the Carriage Return (\r) then even needed for?