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!
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
Nermin Kekic6,971 Points
isNaN("2") returns false, why?
So i went into console and tested this:
The above returned false. I am confused here, because the number 2 is in double quotes and i would think it should be considered string?
If i do this:
var sum = "2" + "2"
So why is isNaN("2") return false?
Thank you for your help. Nermin
Jennifer NordellTreehouse Teacher
Hi there! Not exactly. Some strings can be converted to numbers and others can't. If you type
isNaN("hello") you will get back true. This is a string that cannot be converted to a number. However, the string "27" could be converted to a number without error. When this is the case, it will convert the string to a number.
I highly recommend taking a look at the "Examples" section of this MDN Documentation.
Hope this helps!
edited for additional information