Callback hell is but a term that we are all familiar with; and Promises swooped in offering you to write code in a beautiful, lucid way. If you read this article: You might not need Promises you will see that you can implement callbacks in an easily comprehendible way.
And the article also lists the cons of Promises over Callbacks; one of which is they are incredibly slow. What are your thoughts on this?
Peter Scheler
JS enthusiast
The speed depends on the implementation (e.g. Bluebird isn't slow).
And there are a lot more advantages of Promise:
You can share/fork them
const promise = Promise.resolve('Hi') promise.then(console.log) // at an other place promise.then(txt => console.log(`result: ${txt}`))You can merge/collect them (very useful with
Array.prototype.map)const promise1 = Promise.resolve('Hi') const promise2 = Promise.resolve('there') Promise .all([promise1, promise2]) .then(([txt1, txt2]) => console.log(`${txt1} ${txt2}`))You can still nest them
getUser(id) .then(user => { return getDepartment(user.departmentId) .then(dep => { delete user.departmentId user.department = dep return user }) })And they are the base of the new async/await syntax.