0

So I'm new to using javascript, and I'm confused about how some things work. I've used python quite a bit and I understand it pretty well. I have never come across anything like arrow functions. This has probably been asked tons of times but how do arrow functions work? For eaxmple, using the requests module:

const request = require('request');
request('http://www.google.com', (error, response, body) => {
  //do stuff with error, response, and body
});
console.log(body);

Could someone please tell how I can get the body variable out of the arrow function and get it in the rest of the code? Or in other words, declare it globally for the rest of the code to use.

Greer Page
  • 45
  • 1
  • 6
  • https://stackoverflow.com/questions/111102/how-do-javascript-closures-work?rq=1 See if this helps you understand better. – Zachary Haber Apr 07 '20 at 00:15
  • 2
    Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – SuperStormer Apr 07 '20 at 00:21

0 Answers0