JavaScript math methods I never knew existed

2 min read - posted on 07 Sep 2021

I was trying to break Cloudflare Workers tonight and did a search for "CPU intensive JavaScript" because I'm really good at my job.

This gist popped up with the following code:

function mySlowFunction(baseNumber) {
console.time("mySlowFunction")
let result = 0
for (var i = Math.pow(baseNumber, 7); i >= 0; i--) {
result += Math.atan(i) * Math.tan(i)
}
console.timeEnd("mySlowFunction")
}

mySlowFunction(8) // higher number => more iterations => slower

Cool, cool. It's some loop that does something and returns a... wait a minute what the heck is Math.atan!?

According to MDN it's:

The Math.atan() function returns the arctangent (in radians) of a number

I don't know anything about math so I'm not even going to pretend to understand actangents but it led me to wondering what other math methods I never heard of. Here's a list:


Subscribe to my email list!

Let me be real with you. Sometimes when I'm bored I log in to Buttondown and look at the audience number. If it's bigger than it was the week before, well that makes me feel really happy!

I promise I'll never spam you and I will, at most, send you a monthly update with what's happening on this site.