Preventing callbacks from accidentally being called twice
Asynchronous calls like this are extremely common in JavaScript: fetchFile("example.js", function(fileContents){ console.log(fileContents) }) In order to avoid freezing the user interface while the file is loading, fetchFile returns immediately and then when example.js has been loaded the callback is called with the file contents. Here's
JavaScript Code Readability