I am fairly new to Javascript/Node. But I have some programming expierence around Python, Java and C++. However. I can't seem to figure out the scope of the variables. For instance, I've got a variable named x and a method, which gets via a get request a body of a sepecific website. Now I want to store it in another variable.
My script:
const request = require('request');
var x;
request('http://www.google.com', function(err, res, body) {
return this.x = body;
});
console.log(x); // Should return the "body" from the request method.
returns:
undefined