I am wondering if it's possible to assign the value of callback to a variable. I recently ran into a problem with MongoClient's connect method, where I want to get the db object and pass it on to my class methods. Is there a way I can I assign hello world
to var b
.
function testCB(cb){
setTimeout(() => {
cb('Hello World')
}, 1000)
}
let b = testCB('a', (str) => {
return str;
})
console.log(b) //undefined