liveBook · Manning

Side effect

As explained in Acing the Frontend Interview

A side effect is an observable interaction with state or the outside world that occurs in addition to producing a function's return value.

A side effect is an observable interaction with external state or the outside world beyond producing a return value. Pure functions avoid side effects, making them predictable, testable, and easier to debug. section 3.2

Impure versus pure functions

increment changes the external counter before returning it, so repeated calls depend on prior state. add only computes from its arguments. Similarly, nums.map(n => n * 2) returns a new array without changing nums when its callback is pure. section 3.2

Useful interview checks include:

  • Determine whether console.log inside a function counts as a side effect. section 3.2
  • Explain how immutability and referential transparency support predictable reasoning about code. section 3.2

How Acing the Frontend Interview covers it

How deep it goes
Defines side effects through purity and external state, then probes console output, global reads, and immutable updates.
Examples
Contrasts a counter-mutating increment with pure addition and maps numbers into a new array.
What you can do after
Evaluate whether JavaScript functions preserve predictability and identify interactions with external state.
How it connects
Connects side effects with pure functions, immutability, map, referential transparency, testability, and debugging.

Also explained in

Compare how 28 books explain side effect →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.