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

Kyle Gibbons
Kyle Gibbons
1,388 Points

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

Simon Coates
Simon Coates
28,694 Points

i ran it in browsers console and got 2.

2 Answers

Shawn O'Connor
Shawn O'Connor
14,135 Points

Any non zero number will typically return as 'True'

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

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

Kyle Gibbons
Kyle Gibbons
1,388 Points

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.