[Issue 814] You don’t understand JS: ES6 and the future grammar (part 2)

[Issue 814] You don’t understand JS: ES6 and the future grammar (part 2)

image

Preface

The new year, the new week is already Wednesday, today we continue to look at the translation sharing brought by the front-end morning reading class columnist @HetfieldJoe.


The text starts here~


For better association, please refer to:

[Issue 798] You don’t understand JS: ES6 and the future grammar (part 1)

[Issue 808] You don’t understand JS: ES6 and the future grammar (in)


Digital literal expansion

Before ES5, digital literals looked like the following-the octal form was not officially specified, and the only allowed extension was an extension that various browsers had essentially agreed on:

image


Note: Although you use a different base to specify a number, the mathematical value of the number is what is stored, and the default output interpretation method is always decimal. The three variables in the previous code snippet all store the value 42 in them.


To further illustrate that 052 is a non-standard form of extension, consider the following code:

image


ES5 continues to allow the octal form of this browser extension (including such inconsistencies), except in strict mode, where the octal literal (052) is not allowed. The main reason for this restriction is that many developers seem to be accustomed to subconsciously prefixing the decimal number with 0 in order to align the code, and then encounter the accident that they completely change the value of the number!


ES6 continues the legacy changes/categories that can be represented by numeric literals other than decimal numbers. There is now an official octal form, an improved hexadecimal form, and a brand new binary form. Due to web compatibility reasons, the old octal form 052 will continue to be legal in non-strict mode, but should never be used again.


These are the new ES6 digital literals:

image


The only decimal form allowed is decimal. Octal, hexadecimal, and binary are all in integer form.


And all these forms of string representation can be coerced/transformed into their digital equivalents:

image.png


Although not strictly new to ES6, a little-known fact is that you can actually switch in the opposite direction (well, in a sense):

image


In fact, in this way you can express a number in any base from 2 to 36, although you will use standard bases-2, 8, 10, and 16-very rarely.


Unicode

I can only say that this section is not an exhaustive "everything you want to know about Unicode" information. What I want to explain is that you need to know what has changed to Unicode in ES6, but we will not go deeper than this. Mathias Bynens (http://twitter.com/mathias) has written/explained extensively and brilliantly about JS and Unicode (see https://mathiasbynens.be/notes/javascript-unicode and http://fluentconf.com/javascript -html-2015/public/content/2015/02/18-javascript-loves-unicode).


The Unicode characters in the range from 0x0000 to 0xFFFF include all standard printed characters (in various languages), which you may have seen and interacted with. This set of characters is called the Basic Multilingual Plane (BMP). BMP even contains interesting characters like this cool snowman: ☃ (U+2603).


There are many extended Unicode characters outside this BMP set, and their range is up to 0x10FFFF. These symbols are often called astral symbols, which are the names of 16 groups of planes (ie, layering/grouping) of characters other than BMP. Examples of star symbols include

Guess you like

Origin blog.51cto.com/15080028/2595029