EcmaScript 6 Features 2: Binary and Octal Literals
This week's ES6 feature is binary and octal literals. Generators will be coming next week!
In JS you can specify a number in hex like so:
> 0x3ef
1007
If you wanted to specify a number in octal or binary, previously you would have to use parseInt:
> parseInt("012362", 8)
5362
> parseInt("110010100", 2)
404
If your environment supports it, you can use the new literals.
> 0b110010100
404
> 0o767
503
For octals, you simply prefix the number with 0o (zero then 'o'). For binary, you prefix it with 0b (zero then 'b'). The new octal literal could be used to specify file permissions more easily, I suppose.
The next one in this series will be more interesting :)