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 Numbers and Strings

B G
B G
1,866 Points

Why is numOfDivs already an int?

Tried solving this and got the same answer as many people and it didn't work. Look through the forums and someone stated the numOfDivs was already an Int. I wanted to know why?

1 Answer

Ben Reynolds
Ben Reynolds
35,170 Points

This is partly right, js doesn't have a specific "int" type, just "Number" and it can have decimals or not.

Anyway the reason numOfDivs is already a Number is because it was initialized with a value of 10. In doing so, the javascript interpreter detects this and considers the variable a Number type automatically.

Same thing with width. It sees a value enclosed in quotes and presto. It's a string. This is how 'dynamically typed' languages work. Instead of declaring a variable with a data type up front, you use "var" and let the interpreter figure it out based on the value.