Overview

This page is the atomic definition. The broader principles live at general-principles.

Definition

A side effect is any state change a function makes outside its return value. Examples include mutating an argument, writing to disk, sending a network request, logging to stdout, updating a global variable, or modifying the DOM. A function with no side effects is called “pure”: given the same inputs, it always returns the same output and changes nothing observable in the rest of the system. Side effects are unavoidable in real programs (output is a side effect), but isolating them at the edges of the system makes the core logic easier to test and reason about.

When it applies

Track side effects when writing testable code, functional pipelines, or React components. The React community uses “effect” specifically for side effects triggered by render (the useEffect hook).

Example

// Pure: same input gives same output, no observable change.
function tax(amount: number, rate: number) {
  return amount * rate
}
 
// Side-effecting: writes to console.
function tax(amount: number, rate: number) {
  console.log("computing tax")
  return amount * rate
}

Citing this term

See Side effect (llmbestpractices.com/glossary/side-effect).