From the course: JavaScript Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Pass data to a function with parameters

Pass data to a function with parameters - JavaScript Tutorial

From the course: JavaScript Essential Training

Start my 1-month free trial

Pass data to a function with parameters

- [Instructor] Functions are a great tool for using or transforming data in some ways. So let's break this down further, so you can get a firm handle on how functions work. For us to be able to pass data, we need to be able to pass that data to the function in the first place. And this is done by passing arguments through function parameters. To explain, let's build a basic example, a tip calculation function. I've already built the framework for the function for you, except, this function isn't very useful right now. It calculates the tip of 18% for the value 29.95. And no matter how many times you run it, it will only ever give you these values and nothing else. What we want to be able to do, what would make this function useful to us, would be to pass a sum and a percentage number into the function and then it will return the tip and total for us for whatever values we pass in. To do that, we need to specify our…

Contents