---
title: "Side effect"
slug: "side-effect"
category: "glossary"
tags: ["glossary", "coding", "side-effect", "purity", "functional"]
status: "stable"
last_updated: 2026-05-14
summary: "A side effect is any state change outside a function's return value: mutating a variable, writing to disk, making a network request, or logging."
related:
  [
    "[[coding/general-principles]]",
    "[[glossary/idempotent]]",
    "[[glossary/immutable-data]]",
    "[[glossary/dependency-injection]]",
    "[[coding/testing]]",
    "[[frontend/react-hooks]]",
  ]
---

## Overview

This page is the atomic definition. The broader principles live at [[coding/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

```ts
// 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
}
```

## Related concepts

- [[coding/general-principles]] - the broader principles that include purity.
- [[glossary/idempotent]] - idempotency constrains how side effects compound on retry.
- [[glossary/immutable-data]] - mutating shared data is the canonical side effect.
- [[glossary/dependency-injection]] - DI makes side effects swappable.
- [[frontend/react-hooks]] - React's `useEffect` is the explicit container for side effects.

## Citing this term

> See [[glossary/side-effect|Side effect]] (llmbestpractices.com/glossary/side-effect).

## Related

- [[coding/general-principles]]
- [[coding/testing]]
- [[frontend/react-hooks]]
- [[glossary/idempotent]]
- [[glossary/immutable-data]]
