Promise

Promise Example

// getData() is a Promise
function getData() {
 // return a Promise
 return fetch('https://pwagram-bbfd4.firebaseio.com/posts.json')
   .then(function (res) {
     return res.json();
   })
   .then(function (data) {
     return data;
   });
}

var getBtn = document.getElementById('getdata');

getBtn.addEventListener('click', function(){
 getData().then(function (data) {
   console.log(data);
 });
})

Resources