Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
A function is like a recipe you can use over and over. Write the code once, then "call" the function whenever you need it. Give it ingredients (inputs) and get back a result!
function sayHello() { ... }Write what the function does
sayHello();Run it whenever you need
Define a function and call it multiple times
Function takes input, processes it, gives output
Pass values into functions to make them flexible
function double(number) {
return number * 2;
}
const result = double(5);
// result is 10The return keyword sends a value back, and you can store it in a variable!
function add(a, b) {
console.log(a + b);
}Just prints, can't use the result
function add(a, b) {
return a + b;
}Returns value, can use anywhere
Get results back from functions
Build reusable calculator functions
function greet(name) {
return 'Hello, ' + name;
}const greet = (name) => {
return 'Hello, ' + name;
}Modern, concise function syntax
Write once, use many times
Pass values into functions
Send a value back from function
Modern syntax: (x) => x * 2