DEV Community

Dev Ananth Arul
Dev Ananth Arul

Posted on

Callback hell in JavaScript

Callback hell
Callback Hell, also known as the "Pyramid of Doom," is a phenomenon in JavaScript that arises from the excessive nesting of callback functions, particularly when handling multiple asynchronous operations that depend on each other.

Definition:
Callback Hell describes a situation where deeply nested callback functions lead to code that is difficult to read, understand, debug, and maintain. This structure visually resembles a pyramid or a series of increasingly indented blocks of code.

Example of Callback hell:

    setTimeout(() => {
        console.log("Analysis")

        setTimeout(() => {
            console.log("Plan")

            setTimeout(() => {
                console.log("Design")

                setTimeout(() => {
                    console.log("Development")

                    setTimeout(() => {
                        console.log("Testing")

                        setTimeout(() => {
                            console.log("Deployement")

                        }, 1000);

                    }, 1000);

                }, 1000);

            }, 1000);

        }, 1000);

    }, 1000);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)