Higher Order Function, Callbacks Function, Biggest Problem With Callbacks

Higher Order Function, Callbacks Function, Biggest Problem With Callbacks

Higher Order Function

There are functions which take another function as arguments, these are called high order functions.

No alt text provided for this image

There are some internal functions which are also available as higher order functions. Let's talk about that

No alt text provided for this image
No alt text provided for this image

Callbacks Function

This concept technically exists in every language. If you are coming from the world of JavaScript already then this word callbacks is one of those words that most probably you are going to use daily in your programming career.

Higher order functions consume functions as arguments and the function that you pass as argument is called callback function.

No alt text provided for this image

Biggest Problem With Callbacks

You might say the callback hell but that is the second disadvantage of the callbacks not first. Let's talk about it -

Writing callbacks is kind of? fun but sometimes callbacks become? problematic. Most of the time if you ask someone hey what is the problem with callbacks you find the answer as callback hell but in my opinion callback hell is not the biggest problem that you have.? Why am I saying that ? Because when you talk to the people and you ask what is the problem with callback they say Callback hell the second follow up question should be how can you improve it ? they will start saying Promises can help us avoid callback hell. The problem is in the concept of promises there are promise hell also. But technically you can't improve callback using promises. After that some people say that the callback problem will be solved using async await but there's async await hell.

There is a bigger problem in callbacks that is technically called Inversion of Control.

The control of your function which was your implementation you have passed the control of how this function should be called to someone else. Means In the context of callbacks, inversion of control is the notion of having code under your control in one part of the program, then handing control over to a callback in another part of the program.

No alt text provided for this image

要查看或添加评论,请登录

Shubhasheesh Kundu的更多文章

  • Promises

    Promises

    Promises are to improve code readability. With the help of promises we can solve the problem of Inversion of control.

  • Async Programming With JavaScript

    Async Programming With JavaScript

    Properties of JavaScript JavaScript is sync in nature. JavaScript is single threaded.

  • Function Expression & IIFE

    Function Expression & IIFE

    What are JavaScript functions? Functions are essential building blocks in JavaScript, they are packed with logic for…

  • JavaScript - Boxing Concept

    JavaScript - Boxing Concept

    Primitives- Boxing Concept In JavaScript and other languages, primitive values don’t have methods or properties, so if…

  • JavaScript - 3

    JavaScript - 3

    ToBoolean ( argument ) - The abstract operation ToBoolean converts argument to a value of type Boolean according to…

  • JavaScript - 2

    JavaScript - 2

    Let’s Talk About [Object Object] You might have seen this kind of [object object] string getting printed on web apps or…

  • JavaScript

    JavaScript

    You might find lot of memes or you might find lot of articles were people say that JavaScript is weird Programming…

    1 条评论

社区洞察

其他会员也浏览了