What will be logged to the console? Will the finally
block be executed?
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
To analyze this code snippet, I'll start with the things that are clear:
- the
.then(console.log)
function will not be executed and thereβs a rejection inside of thePromise.resolve()
- the
catch
block wonβt be able to catch the rejection as it happens asynchronously
So, weβre left with the finally
block. Thereβs a single call to the console.log
and itβs the first message the will be printed on the screen.
Then, the unhandled rejection will happen as we havenβt provided the error handler to the promise chain in line 2.
ANSWER: The string finally
will be logged to the console followed by the UnhandledPromiseRejectionWarning: -1
Discussion (0)