I'm developing a web application with Angular 4 (using TypeScript / JavaScript language). Unfortunately I don't know JavaScript and its callback mechanism very well. I have a problem. If I call a method that takes a function as a parameter, such this:
    this.cognitoIdentityServiceProvider.listUsers(params,function(err,data) {
       if (err) console.log(err, err.stack);
       else {
         console.log(data);      
    }
I can use the data parameter only inside the body of function(err,data) and not elsewhere.
If I initialize an external object inside function(err,data), it seems that the object only takes the right value within the function, but 
not externally, as in this example:
var myData = null; // external variable declaration
this.cognitoIdentityServiceProvider.listUsers(params,function(err,data) {
   if (err) console.log(err, err.stack);
   else {
     myData = data;
     console.log(myData); // prints the date value (correctly)  
}
console.log(myData); // print 'null' but I would like the data of 'data' object 
I would be very comfortable with using this data outside function(err,data) to pass them as a parameter. Unfortunately I have no idea how to do it.
 
     
    