Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Functions!
You have completed JavaScript Functions!
Preview
A function can have more than one return statement, but only ever run one based on a condition.
Resources
Code Snippet
function noAlert() {
return 5;
alert("This won't appear");
}
noAlert();
alert("This will appear");
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Until it reaches the end, or is instructed
to stop with a return statement.
0:00
A function can have more
than one return statement.
0:03
For instance, you might create a function
that checks if a form field is empty.
0:06
In this case, the function could
return either true or false.
0:10
The function might check the field,
then return just the value true,
0:14
if the form field hasn't been
filled out by a user, and is empty.
0:18
Or it could return false,
if the user did enter something.
0:22
You can then use that return
value to perform another action,
0:25
like display an error message, or
prevent the form from being submitted.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up