Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Create Functions Using Arrow Syntax 4:34
- Concise Arrow Function Syntax
- Arrow Functions Review 5 questions
- Default Function Parameters 5:11
- Create an Arrow Function 1 objective
- Descriptive Comments for Functions
- Function Challenge 1:24
- Function Challenge Solution 4:28
- Testing for Number Arguments 4:02
- JavaScript Functions Review 6 questions

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Testing for Number Arguments
Resources
- isNaN() – MDN
- 3 Ways to Check if Variable is a Number in JavaScript
- The throw statement – MDN
- Error objects – MDN
- First-class Function – MDN
Functions as First-class Citizens
Functions are often referred to as "first-class citizens" in JavaScript, which means that you have the ability to do almost anything with functions.
You can store a function in a variable:
const multiply = function(a, b) {
return a * b;
};
Pass a function as an argument to other functions:
function sayYay() {
return 'Yay';
}
/*
- The argument passed for 'func' should be a reference to a function
- That function gets called in console.log
*/
function greeting(func, name) {
console.log( `${func()}, ${name}!` );
}
/*
- A reference to the sayYay function gets passed to the greeting function as an argument
- sayYay returns the string 'Yay', so the greeting function logs 'Yay, Lee!'
*/
greeting(sayYay, 'Lee'); // Yay, Lee!
You can even set a function to return another function:
function sayYay() {
return function() {
console.log('Yay!');
}
}
This lets you take advantage of powerful design patterns you'll learn about in later courses.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Kirok James
Full Stack JavaScript Techdegree Student 876 Points1 Answer
-
Peter Huang
5,427 Points1 Answer
-
nasser mohammed
13,160 Points1 Answer
-
Zydrunas Likas
3,952 Points1 Answer
-
Hina K.
4,807 Points1 Answer
-
karan Badhwar
Web Development Techdegree Graduate 18,135 Points2 Answers
-
Yoan Halevy
Full Stack JavaScript Techdegree Student 2,964 Points1 Answer
-
Kade Rathbun
6,586 Points1 Answer
-
ja5on
10,338 Points1 Answer
-
Esther AlQaisi
2,311 Points1 Answer
-
Sara Masek
Front End Web Development Techdegree Student 11,513 Points1 Answer
-
Zach Hope
1,862 Points1 Answer
-
Alexis Scriven
2,246 Points2 Answers
-
Palash Tiwari
8,050 Points2 Answers
-
Vikram Pal
2,832 Points1 Answer
-
Jamie Davies
2,787 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
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