Functions
Reusable blocks of logic. The site's namesake — the function declaration.
Function declaration
Hoisted, so it can be called before it appears in the source.
function greet(name) {
return "Hello, " + name + "!";
}
greet("world"); // "Hello, world!"
Function expression
const square = function (n) {
return n * n;
};
Arrow function
const double = (n) => n * 2;
const add = (a, b) => a + b;