¹Not really, but close enough.
Originally, this was resolved via callbacks:
doSomething((err, result) => { if (err) { ...failure code... } ...success code... }
doSomething().then((result) => { ...success code... }).catch((err) => { ...failure code... });
try { let result = await doSomething(); ...success code... } catch (err) { ...failure code... }
¹Not really, but close enough.
Originally, this was resolved via callbacks:
But that got very clunky, resulting in something called "callback hell" and the "callback pyramid of doom." So promises were introduced: But that's also clunky, so the async/await syntax was introduced: And that's actually quite pleasant to use.