Professional Documents
Culture Documents
34 BasicCallback JS
34 BasicCallback JS
34 BasicCallback JS
task.
If you do not know, in JS we are using callbacks quit a lot. And previously before
asynch/await and Promises we used Callbacks for fetching data.
Also nowerdays Callback is quit popular way to work inside of the application.
Callback allows us to make some asynchronous stuff and wait for the result.
In callback(“done”) we send sometimes the data / the results of the Api call for example.
2 important points
1. Callbacks allow us to do some asynchronous stuff and wait for the result.
Because we provide inside as param a function from outside and it will be called later, not
immediately. This is the main purpose of a callback.
2. And second inside of our asynchronous function we do not know what is a callback function.
That why we can share a generic function without a specific implementation or our callback.
.......
https://www.w3schools.com/js/js_callback.asp
// Create an Array
const myNumbers = [4, 1, -20, -7, 5, 9, -6];
// Display Result
document.getElementById("demo").innerHTML = posNumbers;
Try it Yourself »
https://www.w3schools.com/js/js_callback.asp
https://www.w3schools.com/js/js_asynchronous.asp
Callback Alternatives
With asynchronous programming, JavaScript programs can start long-running
tasks, and continue running other tasks in paralell.
https://www.w3schools.com/js/js_promise.asp
A Promise contains both the producing code and calls to the consuming code.