From the course: Learning the JavaScript Language

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

More on function arguments

More on function arguments

- [Presenter] In this video, we're going to look at arguments and functions a little more. We'll see how to define functions with variable numbers of parameters and how to make arguments optional by defining default values for them. First, I'm going to show this function I've defined called speak something. I've pasted in the code defining function ahead of time so we can look at how it works before we actually see that code, which takes two arguments. Your functions don't have to have only one. They can have as many arguments as you need. Speak something can take two arguments. It takes what to say like good morning and how many times to say it as a second parameter. Five times in this case. And when I call this, it says good morning and also tells me how many times it has said it so far. So you could see that you can have more than one argument, but what if you want to provide default values for some of these? What if I know that I want to say good morning, but I don't care how many…

Contents