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 The Random Challenge Solution

shadryck
shadryck
12,151 Points

parseInt returns Infinity?

I'm curious about why and how this works. Is it related to 32 / 16 bits integers not being able to contain higher numbers or something like that?

parseInt("99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") // returns 1e+308

parseInt("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") // one 9 more returns Infinity

1 Answer

Thankfully the lovely people over at MDN have the answer.

The Number.MAX_VALUE property represents the maximum numeric value representable in JavaScript.

...

The MAX_VALUE property has a value of approximately 1.79E+308. Values larger than MAX_VALUE are represented as "Infinity".

shadryck
shadryck
12,151 Points

Ah, I've totally missed that. Thank you for taking the time to link it.

You're welcome. =)