Monday 20 March 2017

Catching value of an async function

I've got this async function:function fetch(cb) { var data setTimeout(() => data = {"hello":"world"}, 1000) return data } That function returns the value after 1 second, I'm looking to console.log the value when it's ready. It's been said that here we should use callbacks, but wtf, I've tried all the ways and I still get undefined..Any solution would be appreciated, but don't add a console.log inside the timeout function..

Submitted March 20, 2017 at 06:31PM by shark1337

No comments:

Post a Comment