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 Arrays Loop Through Arrays Locate and Join Array Elements

Why 0 doesn't get the falsey if condition.

Hi,

according to the MDN link https://developer.mozilla.org/en-US/docs/Glossary/Falsy and what the videos says, 0(zero) should also be considered a falsey value (along with null and the others

Then why, if you paste the final code on the teacher's note and input 0 on the prompt dialog, you get the message "Sorry, we do not have 0." instead of the result of "in stock:</strong> ${inStock.join(', ')}"??

Thanks!!

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Ricardo Osorio! You're correct that 0 is considered falsy. However, any input that is read in through the prompt is a string. Any non-empty string is considered truthy. So the Number 0 is different than the string "0" in terms of truthiness.

Way to dig into the documentation! Kudos. It took quite some time before I found the documentation understandable enough to make friends with it. It will be crucial going forward. Note that it says:

The Number zero (so, also 0.0, etc., and 0x0).

Hope this helps! :sparkles: