DEV Community

Discussion on: Remembering that "functions are objects" can help in writing more concise code

Collapse
 
robertcoopercode profile image
Robert Cooper
fetch('https://api.github.com/')
  .then(res => {
    return res.json();
  })
  .then(function(data) {
    console.log(data);
  })
  .catch(err => console.log(err));

^ I did not even know that this could be shortened the way you suggested. Thanks for explaining this idea of a stored function definition. I'm not quite sure I've got my head wrapper around the idea, but I believe to have a better understanding now.

Collapse
 
somedood profile image
Basti Ortiz

Thanks! However, as mentioned by jburgy, we do have to be aware of some weird outliers.

You do have to be careful with things like

['0', '1', '2'].map(parseInt)