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

Totally basic JS question here

Trying to get my head around some pretty simple JS can someone explain to me why

if(2 % 3 ) { console.log("True"); } else { console.log("False!"); }

Hi there can someone tell me why this evaluates to True and therefore prints my first statement - is it because it returns a positive value ie the remainder of 2/3 and is there for not a 0 and must be TRUE

G

1 Answer

Hi,

In JavaScript there are truthy and falsy values. The falsy values are: null, undefined, NaN, the empty string, 0, -0 and the keyword false. Everything that is not a falsy value will evaluate to true. so in this case 2%3 is 2, so 2 is a truthy value and it evaluates to true.

I hope it was helpful. Many thanks,

Edu

Cool thanks Eduardo