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) Working With Numbers Review Working with Numbers

Dave Patton
seal-mask
.a{fill-rule:evenodd;}techdegree
Dave Patton
Front End Web Development Techdegree Student 5,209 Points

Won't parseInt() do the same thing as Math.floor(), but faster since you don't have to call up the Math class?

I'm just curious if you this is a more common way to get an integer from a float.

3 Answers

hey ! yeah , well, its not that big difference between the two, but you can use them both ! :)

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Interesting question. I created a simple JavaScript performance test for these two scenarios. As it turns out, Math.floor() is much faster.

http://jsperf.com/test-parseint-and-math-floor

Not sure why, and in actual performance, if you only do this once in a script, it will really make no actual performance difference.

strange but true though, thanks Dave McFarland for your concerne, i personaly really appreciate !