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

Begana Choi
PLUS
Begana Choi
Courses Plus Student 13,126 Points

why 0(zero) is falsey?

I can't understand in this case, why zero is falsey.

function countToFive( start ){ start = start || 1; for ( var i = start; i <= 5; i += 1;){ console.log( i ); } }

countToFive(0)

because in my opinion, it is truthy when the start argument is given.

2 Answers

Begana Choi I'm not really certain how 0's truth value relates to the function you pasted here, and I'm not certain this answers your question, but the explicit number 0 is ALWAYS falsey. If you do a "console.log(0 == false);" it will come out as a true statement because in programming the number 0 is representative of "false" and the number 1 is representative of "true". If this doesn't answer your question, I am going to need you to clarify a little more about the function you pasted and its context.

Begana Choi
Begana Choi
Courses Plus Student 13,126 Points

if I try it on console, 0 == false is true but 0 === false is false. I don't know how == works exactly yet, so I need to get an answer more precisely.. and the question is related with the video of short circuit evaluation!

Begana Choi == is an operator that checks whether or not the value of two things are equal. === is an operator that checks that both the value AND the type of two things are equal. So in this instance 0 === false is false because 0 is a type "number" but the word false is a type "boolean". You can verify this in your console by using the typeof() function. You can do typeof(0) and typeof(false).