From the course: JavaScript Essential Training
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Pass data to a function with parameters - JavaScript Tutorial
From the course: JavaScript Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
The real-world function2m 49s
-
(Locked)
Functions and methods6m 23s
-
(Locked)
A standard function3m 53s
-
(Locked)
The arrow function4m 49s
-
(Locked)
Arrow functions and "this"4m 20s
-
(Locked)
Practice: Build a function1m 31s
-
(Locked)
Pass data to a function with parameters4m 56s
-
(Locked)
Return values from a function7m 1s
-
(Locked)
Practice: Pass values between functions2m 33s
-
(Locked)
Callbacks5m 29s
-
(Locked)
Conditional if...else statement5m 52s
-
(Locked)
Logical operators3m 31s
-
(Locked)
Conditional switch statement5m 55s
-
(Locked)
Looping through content5m 19s
-
(Locked)
Using the map() array method4m 52s
-
(Locked)
Challenge intro: Create a content factory2m 36s
-
(Locked)
Solution: Create a content factory5m 21s
-
-
-
-