Function
ELI5 — The Vibe Check
A function is a reusable recipe. You write the steps once, give it a name, and call it whenever you need those steps done. Instead of writing 'mix, bake, cool' every time, you just say 'makeCake()' and it does all of that for you.
Real Talk
A function is a named, reusable block of code that performs a specific task. It can accept inputs (parameters), execute logic, and return a result (return value). Functions are the primary unit of code reuse and abstraction in most languages.
Show Me The Code
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("Alice")); // "Hello, Alice!"
When You'll Hear This
"Extract that logic into a function." / "This function is doing too many things — split it up."
Related Terms
Method
A method is just a function that belongs to an object or class. Your Dog object has a bark() method — it's the dog's personal function.
Parameter
A parameter is the placeholder name inside a function definition — it's the label on the slot where you plug things in.
Pure Function
A pure function is the well-behaved kid of programming.
Return Value
A return value is what a function hands back to you after doing its work. You send a coffee machine beans and water, it returns coffee.
Side Effect
A side effect is when a function secretly does something beyond just giving you an answer — like changing a global variable, writing to a file, or sending...