Understanding Callbacks and Callback hell in JavaScript : asynchronous behaviour of Javascript Part -1

In most programming languages, functions can accept other function(s) as arguments or return a function. Such functions are called Higher-order functions. In JavaScript, most APIs and Modules can accept a function as an argument to a function. The functions are called callbacks. Structure of callbacks

Note that JavaScript functions behave as objects. We can set a function as an object property or store a function into a variable. JavaScript is a non-blocking programming language. It doesn’t wait or block operation to finish but keeps on executing. For example, consider the case when data is fetched asynchronously, then javascript doesn’t wait for the asynchronous call to get data but keeps executing the next line of code. So in order to do something with the data, we can use callbacks. See the below example in which we use a timeout to wait for the data just like an XHR request which may take some time to complete

Asynchronous callback with  Jquery and a callback function

  CALLBACK HELL Consider the above example in which we use a callback function which is passed as an argument to the $.get function in Jquery. Now what happens when we want to send subsequent requests is that…

Binary Tree,Max Heap, Priority Queue and implementation using Javascript
programming concepts , Javascript / June 9, 2018

Binary tree is a tree in which every node can have maximum of 2 children.In a binary tree data structure , every parent node can have at most two child nodes.Below is an example of a binary tree. The node with value 100 is the root node.The value 50 and 20 are leaves. A max-heap is a complete binary tree (every node has two children apart from leaves) in which the value in each  node is greater than or equal to the values in the children of that node. It means that the value of the root node will be the maximum.For a min heap the value at the root node should be the minimum. Below you can find example of a max-heap. The array representation of the above binary heap is given below.We start indexing from 1 and leave the 0th index.

  As you can understand, for every node with index i ,the left child is having index 2i and the right child is having index 2i+1.The children are filled in from the left  . If we add another number 50 ,then it will be the child  of  14( 4th index).

So while on insertion , heap is…

Share this page in social media platforms