Search⌘ K

Math Extensions

Discover the extended Math and Number methods introduced in ES6 that improve numerical operations and enable more precise coding. Learn how to use new functions such as Math.trunc, Math.sign, and various logarithmic and hyperbolic calculations to write clearer and more effective JavaScript code.

We'll cover the following...

The Number and the Math objects have been extended with many useful methods. There are many new mathematical functions in ES6.

In my opinion, the most useful and semantic addition is Math.trunc, which gives you the truncated integer value of a number.

Node.js
console.log(Math.trunc( 1.99 ));
console.log(Math.trunc( -1.99 ));

Another extension is Math.sign which gives you the sign of a number. Even though the > and < ...