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 trialDave Patton
Front End Web Development Techdegree Student 5,209 PointsWon'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
Ayoub AIT IKEN
12,314 Pointshey ! yeah , well, its not that big difference between the two, but you can use them both ! :)
Dave McFarland
Treehouse TeacherInteresting 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.
Ayoub AIT IKEN
12,314 Pointsstrange but true though, thanks Dave McFarland for your concerne, i personaly really appreciate !