0

I understand the principles of asynchronous functions, but something is not clear to me: Scoping in asynchronous functions.

Example:

    var path = "/my/folder/to/public/data";
    http.createServer(function(request, response){
            /* some malicious code is executed, however */
            path = "/my/folder/to/private/data"
    });

    /* go on, go on, go on, wait here because of an synchronous function. */
    /* while code execution is here, the callback-function of the server is called. */

    fs.readFile(path+"myfile.txt", function(err, content){
            console.log(content);
    });

So, this is only an example. But how does it behave with the scopes/vars?

user229044
  • 232,980
  • 40
  • 330
  • 338

0 Answers0