Callback Function & Asynchronous Call

Introduction

I have not been able to post for a long time due to school, but will try to do better!

The topics of today’s review are callback and asynchronous call.

Callback

Callback function is a function that can be passed in as parameter into a different function. One of the most common examples is the map/reduce method of Array, where callback function can be passed in as parameter. Or, for DOM and html, callback function can be passed in as parameter of event handler.

In this case, Asynchronous call means that this function can be called synchronously or asynchronously.

Async Callback

Function that is called synchronously is initiated instantly. Blocking methods are called synchronously because it waits for some event to get complete. When the function is called and is returning a value, other events cannot be done.

However, since asynchronous call is non-blocking, it does not wait for the results to return. The request and return are managed separately and a callback function takes care of the result.

Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn’t block execution. (https://www.freecodecamp.org/news/node-js-what-when-where-why-how-ab8424886e2/)

Process is faster and more events can be managed and executed using asynchronous function call.

Conclusion

That is the end of today’s post!

0%