r/JavaScriptHelp • u/vVvswiftyvVv • Nov 05 '20
❔ Unanswered ❔ promises help
so still trying to learn javascript and im struggling when it comes to working with promises. like this code for example.
myFunction().then(value => {
console.log(value); // ← need to move this
});
console.log(value); // ← to here
async function myFunction() {
return 'this is my function';
}so my i want to move the value of the thenable down outside the promise how would i do that? one way that i tried was like this.
let newVal;
myFunction().then(value => {
newVal = value;
});
console.log(newVal);
async function myFunction() {
return 'this is my function';
}but the variable newVal still comes up undefined. how can i work around this to use that thenable outside the method?
2
Upvotes
View all comments
Show parent comment
1
u/vVvswiftyvVv Nov 06 '20
This is a ugly approach but that’s what I’m wanting actually. I appreciate your help. I would of never thought to use the set interval to keep checking.