Side Effect
ELI5 — The Vibe Check
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 an email. It's when the function has impact outside its own little world.
Real Talk
A side effect is any observable change that a function causes beyond returning a value — mutating external state, modifying a database, writing to the console, making a network request, or altering a variable outside its scope.
Show Me The Code
let count = 0;
// This function has a side effect — it mutates external state
function increment() {
count++; // side effect!
}
// Pure function — no side effects
function add(a: number, b: number) {
return a + b;
}
When You'll Hear This
"That function has side effects — it mutates the global store." / "Isolate side effects at the edges of your application."
Related Terms
Functional Programming
Functional programming is like cooking with strict rules: no shared bowls, no side dishes contaminating each other, and every dish must be exactly reproduc...
Idempotent
Idempotent means you can do the same thing multiple times and get the same result as doing it once.
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.