When an asynchronous task is initiated, it's pushed to the callback queue once it's completed, and the event loop continuously monitors the queue, moving tasks to the execution stack when the stack is empty.
The second scheduled task uses a Promise to print “Task 2”. This is also added to the queue but it gets priority over setTimeout.
So, even though “Task 1” was scheduled first, “Task 2” will actually run before it.
Callback hell, also known as the pyramid of doom, refers to the complex and nested structure that arises when dealing with multiple asynchronous operations using traditional callbacks. This can lead to code that is difficult to read, maintain, and debug, often resulting in a loss of productivity and increased potential for errors.
Mastering async/await Syntax