🧭Side Effect
Also known as Side Effects
Work a function does on the side. Saving a file is one; so is printing.
Think of it like
Think of it like a cook who also moves your chairs. You asked for soup, not new seats.
Example
Emma's getPrice function also wrote to the log and bumped a counter. Calling it twice in a test gave two different counts.
Why it matters
Hidden side effects are a top cause of bugs that only appear sometimes. Knowing where they live makes code easier to trust.
Definition
Common mistake
Key takeaways
- 1Beyond the answer. Any change to the outside world.
- 2Needed but risky. Programs must have some.
- 3Keep them visible. In a few known places.