What carriage return means

I cannot understand what carriage return means in JavaScript what it does how do we use it and am I going to use it as a daily basis

Challenge: Escape Sequences in Strings

Link to the challenge:

It’s a great question. I’m not sure about the answer, but this is more or less my idea. Computers store binary information. And we need to tell them how to read it. When you open a file or just type text in a text editor, it is encoded and displayed to you.

Normally in the web you see utf-8, a particular type of encoding. The important thing is (if I’m correct) this maps between the characters you see, and how computers see/read them.

There is a particular sequence of numbers that the computer will interpret as a newline (which is similar to carriage return), another sequence is a tab, or a space. They have to have a representation in order for the programs to render them (say, once you reopen a file).

I don’t think carriage return is very common, but newlines and space are. For example,

text = `The best things in life are free`; 
text2 = `The best things 
in life are free`; 
pattern = /\n/;
result = pattern.test(text);
result2 = pattern.test(text2);
console.log(result,result2) 

this gives a good info on carriege return (\r) and its resemblence with new line

In this context “carriage return” is just an example and you don’t have to pay attention to that or know what it is :wink:

1 Like