Ask coding questions

← Back to all posts
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?

Answered by malvoliothegood (174) [earned 5 cycles]
View Answer
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 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);
  } catch (err) {