Why this function doesn't cause stack overflow

Viewed 54
  1. Code which doesn't cause stack overflow
const s = async () => {
      await new Promise((resolve) => {
        setTimeout(resolve, 1);
      });

      await s();
      console.log("exit");
};

    s();
  1. Code causes stack overflow
const s = async () => {
      await s();
      console.log("exit");
 };

    s();

Question:

case 2 causing stack overflow is what i have expected, what i don't understand is what why case 1 won't. Please help me with this.

0 Answers
Related