JS — Callback hell

Youngmin Park
2 min readMar 29, 2021

Callback Hell

what is callback hell?

Callback Hell, also known as Pyramid of Doom, is an anti-pattern seen in code of asynchronous programming.

Pyramid of doom

It is a slang term used to describe and unwieldy number of nested “if” statements or functions.

below picture is also example of callback hell

callback hell

Let’s make some functions that print something see the below

let’s try on the browser.

open index.html you will see this message

prompt ‘id’
prompt ‘password’

if you put right ‘id’ and ‘password’

this message will show up.

successful!

if you put ‘wrong’ info then this Error message show up on the console.

Error

but there is problem about callback hell in this code.

the main issue is readability. when this callback chain getting longer and longer. it will be harder and harder to find where the error is.

I will talk about more about promise and async and await for next story.

Thank you

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