From a wiki definition on callbacks, a callback is a piece of executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at some convenient time.
//Example events in the web //To find an element by its id in Webpage HTML var el = document.getElementById("button"); //To register for an event 'click' on the button el.addEventListener("click", );
Check an example code on registering to events in JSFiddle example
Understanding the single threaded app
- a web request to get facebook user details
- a database call to get a user record
- receive data on a web socket
- and more
Each of these tasks takes time as shown in the picture. In a traditional multi-threaded language, the flow of the application waits for the responses from each of these services. And so a practise of using them in a new thread is encouraged.
- Some HTML5 APIs such as the File API, Web Database API