Posts

Showing posts from December, 2023

Callback function in JavaScript

Image
Callback function in JavaScript What is a callback function in JavaScript? A callback function is a function that is passed as an argument to another function and is executed after the first function has completed its task. Callback functions are useful for handling asynchronous events, such as network requests, file operations, or timers. For example, you can use a callback function to display the result of a calculation after the calculation is done. Callback function in JavaScript Here is a simple example of a callback function in JavaScript: // Define a function that takes a callback as an argument function sayHello (callback) { // Do some task console .log ("Hello, world!"); // Invoke the callback function callback (); } // Define another function function sayGoodbye () { // Do some task console .log ("Goodbye, world!"); } // Call the first function and pass the second function as a callback sayHello (sayGoodbye); // The output will be: // Hello, wo

Popular posts from this blog

403. Scientific Problem - C++ / C - Solution - Codeforces ACMSGURU problemset

Version Control with Git: A Beginner’s Guide

Callback function in JavaScript