011. Functions as Data
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
In JavaScript, functions are 'First-Class Citizens'. This means they can be assigned to variables, returned from other functions, and most importantly, passed as arguments. A callback is simply a function that is executed after another function has finished executing—hence the name 'call back'. This is the primitive way JavaScript handles asynchronous operations before Promises were introduced.
022. The Pyramid of Doom
While powerful, callbacks have a major downside: readability. When you have multiple asynchronous operations that depend on each other, you end up nesting them. This creates a deeply indented structure known as 'Callback Hell' or the 'Pyramid of Doom'. This makes the code extremely difficult to debug and maintain, which is why modern JavaScript evolved to use Promises and Async/Await.
?Frequently Asked Questions
What is a Promise in JavaScript?
A Promise is an object representing the eventual completion (or failure) of an asynchronous operation, allowing you to attach callbacks instead of relying on heavily nested code.
How do async and await work?
The 'async' keyword makes a function return a Promise. Inside that function, the 'await' keyword pauses execution until the Promise resolves, making asynchronous code look synchronous.
What is the Fetch API?
The Fetch API provides a modern, global interface for making asynchronous network requests (like getting data from an external server) and returns a Promise.
