0

const name = async() => {
  setTimeout(() => {
    return Promise.resolve("1")
  }, 1000);
};

(async function() {
  console.log("hello2");
})();

const timer = async() => {
  console.log(await name());
  console.log("hello4");
};
timer()

expected output:

hello2
1
hello4

output is:

hello2 
undefined
hello4

If i removed the settimeout function and return a promise alobe like this

const name = async () => {
    return Promise.resolve("1")
};

function is returning 1 and it is getting resolved, what is the issue with when i am returning with settimeout function

deceze
  • 491,798
  • 79
  • 706
  • 853
Jerrin stephen
  • 196
  • 1
  • 11
  • Please [edit your previous question](https://stackoverflow.com/posts/62381734/edit) instead of re-posting it. – Bergi Jun 15 '20 at 08:06
  • @Bergi i am not understanding it , can you explain this how works. i have edited my previous question too. – Jerrin stephen Jun 15 '20 at 08:07

0 Answers0