📋 Sequential Promise Execution
Category: js / promises
Difficulty: medium
To execute promises in sequence, chain them using reduce or an async loop. ✅ Using Array.prototype.reduce [code example] Each current must be a function returning a promise. 🧪 Example: [code example] Output: [code example] ✅ 2. Using async/await loop (more readable) [code example] Same usage as above. Notes: Promises start only after the previous one completes . Use when order matters (e.g. file writes, dependent API calls). If each promise depends on the result of the previous , you need to pass the previous result forward . Use an async/await loop and chain results explicitly. ✅ Pattern: Sequential dependent promises [code example] Each task is a function that accepts the previous result and returns a promise. 🧪 Example: [code example] ✅ Behavior: Passes value from one promise to the next. Works with both sync and async returns. Use case: chained API calls, data transformation pipelines. <!-- quiz-start --> Q1: Why must the tasks array contain functions that return promises, rather than promises directly? [ ] Functions are more memory efficient [x] Promises start executing immediately when created; functions allow delayed execution until the previous task completes [ ] It's required for the reduce pattern to work [ ] Functions provide better error handling...