InterviewHubPRO
Section Overview
Q449

Question 449 of 521

Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

86%
JavaScript Internals (521 Qs)•Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

What are the differences between pure and impure functions?

Some of the major differences between pure and impure function are as below,

Pure functionImpure function
It has no side effectsIt causes side effects
It is always return the same resultIt returns different result on each call
Easy to read and debugDifficult to read and debug because they are affected by external code

Practical Code Example

javascript
// Pure Function (No side-effects, predictable):
const add = (x, y) => x + y;

// Impure Function (Modifies external variable / depends on external state):
let count = 0;
const increment = () => { count++; return count; }; // Side-effect mutation!