NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 10

What is callbacks in node js

Callbacks in Node.js are functions that are passed as arguments to other functions and are executed after the completion of some asynchronous operation.

Callbacks are widely used in Node.js to handle asynchronous operations.

However, as applications grow, using callbacks can lead to callback hell or the pyramid of doom, where code becomes nested and hard to read.

To mitigate this issue, developers often use other patterns like Promises or async/await, which provide more readable and maintainable code for handling asynchronous operations.

Here's is the Code !!

// Asynchronous function with a callback
function fetchData(callback) {
    setTimeout(() => {
        const data = "Hello, callback!";
        callback(data);
    }, 1000); // Simulating a delay of 1 second
}

// Using the fetchData function with a callback
fetchData((data) => {
    console.log(data); // Output: Hello, callback!
});

Chapter 9

Some core modules example in node Js.

Previous chapter

Chapter 11

What is promises in node js

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex