JS callback-promise

Youngmin Park
Apr 5, 2021

Promise is a JavaScript object for asynchronous operation.

state: pending -> fulfilled or rejected

Producer vs Consumer

the executor runs automatically.

when new Promise is created, the executor runs automatically.

we can make some delay.

promise.then

I use setTimeout with 2000 millisecond.

park printed after 2 second later.

but how to catch error?

.catch

we use reject instead of resolve. and add .catch after .then

and lastly

.finally

.finally

.finally(). it print always at the end whether it is resolve or reject

I will write more about this later.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Youngmin Park
Youngmin Park

No responses yet

Write a response