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 Functions Arrow Functions Testing for Number Arguments

In this video when they use " if () " How come there is no " else " and still works?

In this video when they use " if () "

How come there is no " else " and still works?

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 37,341 Points

Hi Peter. So i guess the short answer is that "else" is not required on any "if" statement.

if (isNaN(lower) || isNaN(upper) ) {
   throw error
}

return .....

In this example Gil wants to throw an error if either input is not a number. So if the condition in the If is true it will throw an error and exit the function. If the argument is not true then the code in the If block will not run and the code will run after the If.

Gil could have put the return in an else block but here it is not necessary since the throw error will exit the function.

Hope this helps Peter and be sure to post back to the Treehouse Community if you are still confused.