- 720p
- 540p
- 360p
- 0.50x
- 0.75x
- 1.00x
- 1.25x
- 1.50x
- 1.75x
- 2.00x
We hope you enjoyed this lesson.
Cool lesson, huh? Share it with your friends
About this lesson
Implementing and invoking blocks of code with functions.
Exercise files
Download this lesson’s related exercise files.
Functions59.1 KB Functions - Solution
59.1 KB
Quick reference
Functions
A function is a block of code meant to perform a specific task that you can call from anywhere in your program.
When to use
Use functions whenever you need to create a block of code that may be re-used whenever needed.
Instructions
To create a function:
function myFunction(parameter) {
// do something
}
To invoke a function:
myFunction();
You can pass parameters into your function by typing them when you invoke the function.
myFunction(parameter);
Functions only run when they are invoked. They can be run at any time, or many times.
Hints & tips
- Functions are blocks of code that you invoke when needed
- You can pass parameters to functions and get things returned
Lesson notes are only available for subscribers.