Numbers and Math in ES6
We'll cover the following...
We'll cover the following...
In ES6 there are a bunch of additions to Numbers and the Math object. There are new Number literals, Binary and Octal, as well a ton of new methods for Math.
Binary Literals
In ES6 we have to ability to create binary literals. In order to do this we need to prefix our binary number with 0b or 0B.
Javascript (babel-node)
console.log(0b001) // The number 1console.log(0b010) // The number 2console.log(0b011) // The number 3console.log(0b100) // The number 4
If you have never worked with binary numbers before, the pattern goes like this: Starting for the right to the left, the smallest number is as far right as possible. For example 0001 in binary is 1.
| 8 | 4 | 2 | 1 |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
If we wanted to get the numbers 3 it would ...