Promises are a concurrency primitive, first described in the 80s. Now they are part of most modern programming languages to make your life easier. Promises can help you better handle async operations.
An example can be the following snippet, which after 100ms prints out the result
string to the standard output. Also, note the,catch
which can be used for error handling. Promises are chainable.
new Promise((resolve, reject) => { setTimeout(() => { resolve(‘result’) }, 100) }) .then(console.log) .catch(console.error)
Question and answer is powered by AnsPress.io