Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Introducing Functions

What does the code inside the Math.random() function actually look like? How can I find that out?

Just curious if there is a place to see what the default JS functions actually look like... I'm curious how they are built to begin with.

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Ori,

It's hard to actually see the original source code for all browsers as it's part of the built-in JavaScript engine, however Chrome use their own in-house V8 engine which is open source so you can see all the behind the scenes stuff in one file.

https://github.com/v8/v8-git-mirror/blob/master/src/math.js#L134

Hi Ori,

Perhaps this Stackoverflow post can help point you in the right direction.

Cheers

Thank you Chris Upjohn and Robert Richey