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

Peter Huang
Peter Huang
3,314 Points

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 33,545 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.