JavaScript | Callbacks

JavaScript callbacks can be used to process the result of async operation. Lets take a example below.

As shown in below example the callback function is used to process the response received from rest service.

See the Pen by Rohan (@rohanlopes20) on CodePen.


Things gets complicated when we have to call more than one request on after another like second request is depending upon response of first request. This leads to callback hell. I recommend to read more on https://javascript.info/callbacks

As you chain more and more calls it becomes complicated to maintained code. This can be avoided with JavaScript Promises.

See the Pen by Rohan (@rohanlopes20) on CodePen.

Comments

Popular posts from this blog

Spring | Using TIBCO EMS with Spring framework

TIBCO | For Loop - Accumulate output

TIBCO | JNDI Server & JMS Instance creation