View on GitHub

reading-notes

Node Ecosystem, TDD, CI/CD

It does something to each item in an array, and then returns something (if you choose to do so, otherwise returns undefined) which allows you to make a new array after the changes from the whole process.

 

This function something to each item in an array, in this case a function of your choosing, but it also has something called an “accumulator” which is just a value that persists between function calls.

 

let urlRawData = superagent.get('url.com/here'); // not a real url
let data = urlRawData.body;
console.log(data); 
// expected result: a json file/object

 

superagent.get('url.com/here') // not a real url
  .then( urlRawData => {
    let data = urlRawData.body;
    console.log(data);
  }) 
// expected result: a json file/object

 

async function getData () {
  let urlRawData = await superagent.get('url.com/here'); // not a real url
  let data = urlRawData.body;
  console.log(data);  
}
// expected result: a json file/object

 

They are just as they sound, the program “makes a promise” to a part of the code that “I’ll get back to you once you’re finished doing what you are doing”, and then (which is the .then() part) I’ll do something with the result

 

Not all of them, because some callback functions need the result of something else, or the rest of the code needs the result of the callback, so not all functions can be asynchronous.





Go back to table of contents