The reason why its not possible is: The function that called setTimeout will finish executing and return before the function you pass to setTimeout is even called.
What I don't understand: Even if the outer function has finished executing, since its a a setTimeout and not just an inner function, it is scheduled to execute later. That means function I pass to setTimeout WILL execute regardless of outer function. If I add a console.log to my setTimeout function, it will log because said function will get executed so why cant I return a value then?
function x () {
setTimeout(() =>{
console.log("logging")
return "hello"
}, 2000)
}
x()
function x () { //here it makes sense that nothing gets returned as inner function is not called
return () =>{
console.log("logging")
return "hello"
}
}
x()