What is the basic function syntax (no args)
function greet() {
console.log("Hey there");
}What is the basic function syntax with arguments?
function greet(title, name) {
console.log(`Hey there ${title} ${name}!`);
}When should you use a return statement?
Whenever you want to reuse or store the result of a function (which is most of the time!)
You can write your return statement plus code on the same line.
What is a function expression?
AKA an anonymous function.
When you assign a function to a const variable - you do not need to declare a function name.
You can then use this const with arguments in the same way you would use a function.
Eg:
// Function Statement
function add(x, y) {
return x + y;
}// Function Expression (Anonymous)
const sum = function (x, y) {
return x + y;
}What is hoisting?
Hoisting allows you to access to variables and function declarations before they are defined.
This is considered bad practice however.