Suggest an editImprove this articleRefine the answer for “Stateless function”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A **stateless function** is a function that does not store or change internal data between calls: it always behaves the same way for the same set of input arguments. **Key point:** the result of such a function always depends only on the input data, not on context.Shown above the full answer for quick recall.Answer (EN)Image**In short:** A **stateless function** is a function that **does not store or change internal data between calls**. It **always behaves the same way** for the same set of input arguments. --- ### Detailed explanation A "stateless" function remembers nothing about past calls and does not depend on external changes. Every call is an **isolated computation**, fully determined by its input parameters. That is, such a function: - has no **internal memory** (no counters, caches, flags); - does not use **global variables**; - does not change anything outside itself (the DOM, files, network requests). --- ### Example of a stateless function ```javascript function sum(a, b) { return a + b; } console.log(sum(2, 3)); // 5 console.log(sum(2, 3)); // 5 - always the same ``` Each call is fully independent - the result depends only on the input data. --- ### Example of a function *with* state ```javascript let counter = 0; function increment() { counter++; return counter; } increment(); // 1 increment(); // 2 - the result depends on the previous call ``` Here the function "remembers" state (`counter`), so it is **stateful**. --- ### Where stateless functions matter - In **functional programming** - the foundation of pure computations. - In **React** (for example, "stateless components") - components that simply render data without their own state. - In **testable code** - predictable results without dependence on the environment. --- ### SUMMARY | Trait | Stateless function | |---|---| | Stores data between calls | No | | Changes external state | No | | Depends only on arguments | Yes | | Always returns the same result for the same input | Yes | | Example | `Math.max(a, b)` | --- **In one phrase:** > A stateless function is a function that has **no "memory" of past calls**, > and its result always depends **only on the input data**, not on context.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.