JavaScript escape characters, what are escape characters? The difference between (\n) and (\r)

What are escape characters

Escape characters are special symbols used in computer programming to represent some special characters or control characters .

It is prefixed by a backslash (\), followed by one or more characters to represent the desired character or operation.

For example, \n represents a newline character, \t represents a tab character, \ represents a backslash itself, \" represents a double quote, and \' represents a single quote. In some cases, these characters may be Are interpreted as characters with special meaning rather than literal characters . Therefore, escape characters play a very important role in programming.

 JavaScript escape characters

In JavaScript, an escape character is a special character sequence used to represent some special characters or character combinations that cannot be directly represented or entered into the code under normal circumstances.

Common JavaScript escape characters include:


Original link: https://blog.csdn.net/jiang7701037/article/details/80754163

By using escape characters, you can represent and use these special characters correctly in JavaScript. For example, you can use \n to represent a newline character so that the text breaks correctly when outputting it.

The difference between line feed (\n) and carriage return (\r) 

The name of this thing comes from the typewriter. In the past, when you wanted to start a new line, there were two steps:   
    
  1. The typing machine head returned to the starting position, which is the carriage return.   
  2. The paper was pushed up one line, which was the line feed.   

  Nowadays, the carriage return and line feed on the computer is actually a whole concept.

Line feed (\n) and carriage return (\r) are two different ways of expressing line breaks in computers.

The carriage return (\r) is a control character used to move the cursor to the beginning of text.

Newline (\n) is also a control character used to move the cursor to the beginning of the next line.

In Windows operating systems, a newline is usually represented as a carriage return followed by a newline character (\r\n), while in Unix and Linux operating systems, only a newline character (\n) is used without a carriage return character.

Therefore, care needs to be taken to use correct line breaks when using different operating systems or programming languages. Failure to do so may result in code errors or inconsistent display.

The origin of the term "Enter":  
   Regarding the origin of the "Enter key", we have to start with the mechanical English typewriter. On the mechanical English typewriter, there is a part called the "character carriage". Every time a character is typed (originally a word, but I personally think it should be a character here), the "character carriage" advances one frame. When a line of characters is filled, the typist has to push the "cart" to the starting position. At this time, the type machine will respond with two actions: one is that the "cart" is returned to its position, and the other is that the roller rolls up a line to start. Enter the next line. This action of pushing the "cart" is called "Enter". Later, on electric English typewriters, people added a key that directly acted as a "carriage return" key. This new key is called the "Enter key". Later, the concept of "carriage return" was also borrowed in the development of computers.


"Line wrap" is an operation or action:
  Line wrap: On a computer, editing software is generally used to end a line of text input and move the cursor to the beginning of the next line.

Guess you like

Origin blog.csdn.net/weixin_40381947/article/details/131376314