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 Introducing Conditional Statements

Are these two if statements equal?

When testing whether the lower or upper arguments for this challenge are numbers, can I use either of these two statements? Thanks

if ( isNaN(lower) || isNaN(upper) ) {

throw new Error('Please select a real number');

}

and

if ( isNaN(lower)===true || isNaN(upper)===true ) {

throw new Error('Please select a real number');

}

1 Answer

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Both if statements are checking the same thing, one is less typing, contains clarity than the other so you should choose that, which is your first if statement condition. You don't need to add the strict equality operator as the method isNaN will return a boolean value and the default check for an if condition is set to true you can omit it:

if ( isNaN(lower) || isNaN(upper) ) {

To conclusion, you can use both, but the first and example here are both best practice methods.

Thanks again, Jaimie!