I have defined a function by using let and then created a function. This function send a post request to an api and get data in json format. In this function I have used a variable and set it equal to the value of the response.
when I use this function all works fine. whenI use this variable outside the function then I get undefined value''
below is my code
var request = require("request");
let conkey = 'Some Value', //varialble for consumer_key
consec = 'Some Value', //varialble for  consumer_secret
tkn = 'Some Value', //varialble for token
tknsec = 'Some Value',
value;
function myFunction() {
request.post('someurl', {
    oauth: {
        consumer_key: conkey,
        consumer_secret: consec,
        token: tkn,
        token_secret: tknsec
    },body: {"skillIds": [some value]
},json: true}, function (err, res, body) {
    if (err) throw new Error(err);
    value = body.sonething.something;
    console.log(value);  ////THIS WORKS FINE
});
};
myFunction();
console.log(value);  ////This prints Undefined
 
     
    