[JS] Add additional pros for Promises (#152)

* added additional pros for promises

* Update javascript-questions.md

* Update javascript-questions.md
This commit is contained in:
Farhad Jabiyev 2019-01-15 08:28:04 +03:00 committed by Yangshun Tay
parent b3779f010a
commit 676c8d99de
1 changed files with 10 additions and 0 deletions

View File

@ -761,12 +761,22 @@ Some common polyfills are `$.deferred`, Q and Bluebird but not all of them compl
* Avoid callback hell which can be unreadable.
* Makes it easy to write sequential asynchronous code that is readable with `.then()`.
* Makes it easy to write parallel asynchronous code with `Promise.all()`.
* With promises, these scenarios which are present in callbacks-only coding, will not happen:
* Call the callback too early
* Call the callback too late (or never)
* Call the callback too few or too many times
* Fail to pass along any necessary environment/parameters
* Swallow any errors/exceptions that may happen
**Cons**
* Slightly more complex code (debatable).
* In older browsers where ES2015 is not supported, you need to load a polyfill in order to use it.
###### References
* https://github.com/getify/You-Dont-Know-JS/blob/master/async%20%26%20performance/ch3.md
[[↑] Back to top](#js-questions)
### What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?