Q:

Explanation about Javascript function inside function?

I've been learning about js for a while, I almost understand about its main concepts such as prototype, oop ... however I can't understand how this works:
User.findOne().where('socialid').equals(id).where('socialnetwork').equals(snw).exec(function (arr,data) {
    if(data){
    res.send(data);
    }
});

What I don't understand is how data and arr variables are passed to the function inside the exec() function. Is it a closure ? Can anybody give a more simple and intuitive example how it execute behind the scene ?
EDITED: actually, I do understand the callback behavior, what I can't understand is data supposed to be a result by User.findOne().... not from inside the callback function of exec() and it only passed the new function to the exec() as I can see in the code.
Thank you so much

A:

The source code of exec will look something like this:
function exec(someCallback) {
    // ...
    var arr = /* ? */;
    var data = /* ? */;

    someCallback(arr, data);
    // ...
}

