Why it still returning promise at the end is this behavior of repl?
mandaputtra (0)

This code should not return promise at the end, right?

https://repl.it/@mandaputtra/UnderstandAsyncAwait

You are viewing a single comment. View All
malvoliothegood (174)

I have altered your code a little so it works a bit better. I think the Promise returning undefined is a peculiarity of the repl.it environment. You can see from the screenshot of the Firefox console (when I run the code in it) that the promise is fulfilled.

function clearance(data) {
  if (typeof data !== 'string') {
    throw Error('Data must be a string!');
  } else {
    return 'Success';
  }
}

async function getThis() {
  try {
    const result = await clearance(100);
    console.log(result);
  } catch (err) {
    console.log(err.message);
  }
}

getThis();