Javascript closures as a way to retain state


Long time no blog! Let’s get back into it with a nifty and clean way of retaining state in Javascript - closures. I was recently looking for an easy way to call a specific function after two separate/unrelated AJAX calls to two remote endpoints have been completed. The naive method would be to make the first AJAX call -> callback to the second AJAX call -> callback to doSomething, but we can use the fact that these two AJAX calls are not related and run them concurrently.