JAVASCRIPT
06: FUNCTIONS
What are functions and their headers, calls, parameters, and returns?
WHAT IS A FUNCTION
FUNCTION HEADER
function square(num) {
return num * num;
}
function name(parameter1, parameter2, parameter3) {
// code to be executed
}
Header
CALLING A FUNCTION
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
let value = toCelsius(77); // function calling
value = (5/9) * (77-32);
WHAT IS A PARAMETER
WHAT IS AN ARGUMENT
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
let value = toCelsius(77);
Parameter
Argument
FUNCTION RETURN
// Function is called, the return value will end up in x
let x = myFunction(4, 3);
function myFunction(a, b) {
// Function returns the product of a and b
return a * b;
}
TRY IT YOURSELF
Go to onecompiler.com/javascript
Create a function that concatenates strings, try calling it, and see what else you can do!
FUNCTIONS REVIEW
Go to gimkit.com/join
THANKS!
Any questions?
codingpower101@gmail.com
codingpower.org