This course has been updated! We now recommend you take the JavaScript: From First Steps to Professional course.

Check out a free preview of the full JavaScript: From Fundamentals to Functional JS, v2 course:
The "Passing Arguments" Lesson is part of the full, JavaScript: From Fundamentals to Functional JS, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Bianca demonstrates how functions passed as arguments can be invoked using their parameter name. These function may also have their own set of arguments passed to them when they are invoked.

Get Unlimited Access Now

Transcript from the "Passing Arguments" Lesson

[00:00:00]
>> Bianca Gandolfo: So what about passing arguments to functions? So here we have this increment function. And I apologize for this example, it's the most cliche example, but here we are. So we have an increment function, right, we're defining a function, it takes n and it returns n + 1.

[00:00:20] Then we have the square function, it takes n and it returns n times n, okay? So this one's gonna square it, this one's gonna increment it. And this is our function, it says doMathSoIDontHaveTo. This function takes n and it takes a callback function, and it returns that function with n passed to it.

[00:00:42]
>> Bianca Gandolfo: Anyone have a question about what I just said?
>> Bianca Gandolfo: Okay, so, doMathSoIDontHaveTo takes n and it takes a function. Returns that function with n invoked as an argument. So in this case, doMathSoIDontHaveTo takes 5, so n is 5, square, right, this function as func. And so this is square with 5 which equals, 25, yeah.

[00:01:19] [LAUGH] You guys make me laugh.
>> Bianca Gandolfo: So not interested in entertaining me like a kindergartner. So this one is doMathSoIDontHaveTo, we pass 4, n is 4, increment, which is this function that increments. Func is increment and we return increment n, which is then?
>> Speaker 2: 5.
>> Bianca Gandolfo: Yeah, I was thinking it was 6 for some reason but it's 5.