First, this is a very specific case of doing it the wrong way on-purpose to retrofit an asynchronous call into a very synchronous codebase that is many thousands of lines lo
You can also convert it into callbacks.
function thirdPartyFoo(callback) { callback("Hello World"); } function foo() { var fooVariable; thirdPartyFoo(function(data) { fooVariable = data; }); return fooVariable; } var temp = foo(); console.log(temp);