ES6 (string)

ES6 adds new string features

First, the representation of Unicode

 When code value > 2 bytes (0xff)

i.e. the first number is not processed and not displayed

To handle this situation of more than 2 bytes, wrap it with {}

API

1. ES5

Code value > 2 bytes, length 2

2.

1 and 2 are the characters of the first position and the second position, 3 and 4 are the code values ​​of the first position and the second position,

The characters are garbled, but the code value can be taken out. That is, the handling of Unicode in ES5 is not in place.

 During ES6

 In ES6, the codePoint API is added to get the code value of the character. In order to know what character the code value corresponds to, set the second one to hexadecimal

 When 1 is taken, the last two bytes of the character are taken

When taking 2, it is a

3.

ES5 (garbled)

 

In ES6 (correct result)

 

The difference is whether it can handle characters in Unicode

4. The convenience of strings

ES5

 

During ES6

5. Determine whether the string contains certain characters

6. Determine whether the string starts and ends with certain characters

 

7. Repeat

8. Template Strings

9. API in ES7 draft

The function of padding, that is, the string returned by the API must meet the constant 2 satisfied by the first parameter. If the length is not enough, the second parameter will be supplemented. (select date)

10. Label Template

abc is a function

 Function: 1. Filter strings to prevent xss attacks

            2. Handle multilingual conversion

 11.String.raw

raw escapes all \, thus ensuring that \ does not take effect.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326388066&siteId=291194637