February 2018
Intermediate to advanced
298 pages
8h 22m
English
Just as we discussed earlier, JavaScript also exposes some functions to perform logarithmic and exponential calculations, which are quite handy in a lot of situations (especially when you're creating games).
The following example code, which shows all arithmetic-related methods added to the Math object:
console.log(Math.log2(16)); //log base 2console.log(Math.log10(1000)); //log base 10console.log(Math.log1p(0)); //same as log(1 + value)console.log(Math.expm1(0)); //inverse of Math.log1p()console.log(Math.cbrt(8)); //cube root of a value
The output is as follows:
43002
Read now
Unlock full access