why do we need promises in javascript code example
Example 1: promises in javascript
myPromise.then(
function(value) { /* code if successful */ },
function(error) { /* code if some error */ }
);
Example 2: making promises in js
getData()
.then(data => console.log(data))
.catch(error => console.log(error));