I playing around with something like this
function myFunc(){
var val = 10;
new Promise(function(resolve,reject){
setTimeout(function(){
//
val = 20;
resolve();
},1000)
}).then(function(){
return val;
})
}
var val = myFunc();
console.log(val);
Here I'm expecting 20
in output but getting undefined
. What's wrong here ?
Fiddle link: https://jsfiddle.net/nvLc60bm/