Preface
A few years ago, when SpiderMonkey implemented strict mode, I learned that strict mode disables the writing of octal integer area. Because there is evidence that some newbies will use leading 0s to align numbers in multiple rows, resulting in unexpected results:
var sum = 015 + // is equivalent to 13 in decimal, not 15 197 + 001; // Anyway, it is 1console.log(sum) // The sum obtained by addition is 211, not 213 as newbies think
However, some developers still need octal integers (especially those Mozilla extension developers and node.js developers), and the most common one is when processing file permissions (755, 644). Therefore, ES6 has added a new octal integer writing method. Similar to hexadecimal 0x or 0X, the new octal integer uses 0o or 0O as the leading identifier, followed by several octal numeric characters (0 to 7). This writing method will no longer bother newbies:
var DEFAULT_PERMS = 0o644; // Also available in strict mode
It is worth noting that the readability of the 0O prefix is too poor (0 and uppercase O look too similar and it is difficult to distinguish). I raised this question on esdiscuss, hoping to disable the uppercase 0O prefix. However, TC39's current decision still believes that consistency should be greater than readability (consistency means that it should be consistent with 0X and 0B). I think this decision is debatable, and I recommend that you never use uppercase 0O.
In addition, some developers also need binary integer surface quantity writing method, which has never been supported by ECMAScript. ES6 supports this writing method, similar to octal and hexadecimal, using 0b or 0B prefixes:
var FLT_SIGNBIT = 0b1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Currently Firefox Aurora has implemented these two syntaxes. If you are more adventurous, you can also use the updated Firefox Nightly.
Summarize
The above is the entire content of this article. I hope the content of this article will be helpful to everyone in learning ES6. If you have any questions, please leave a message to communicate.