Numbers and Math in ES6
Understand the new number systems introduced in ES6 such as binary and octal literals, and learn how to perform math operations with them. Explore several new Math methods including Math.trunc, and see how these features make working with numbers in JavaScript more versatile and efficient.
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.
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 ...