Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!