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) Making Decisions with Conditional Statements Combining Multiple Tests Into a Single Condition

I'm wondering why the attached code is 1, and not true. I ran it through repl.it, and thought I would get true, reason?

var x = 2;

x || true

i ran it in browsers console and got 2.

2 Answers

Any non zero number will typically return as 'True'

Im going to say its beause x is not a zero or one which reflects the boolean value of false or true. 2 isnt a boolean value

Hey Cindy,

Thank you, I believe that might be why. I actually meant 2 in my question, when I changed x = 0, it came back true.