How does node change variables outside functions

  node.js, question
function findUrl(url, collection) {
 url: url
 }).toArray(function (err, docs) {
 if (docs.length > 0) {
 result = {
 original_url: docs[0].url,
 short_url: docs[0].shorterUrlNum
 console.log(result);  //<-get data from the database and change the value of result
 console.log(result);  //<-the values shown here have not changed before the assignment.
 return result;

Here I guess it should be asynchronous, but how can result be changed?

It is the asynchronous disaster. Please send the callback to findUrl. if you get the result, you will find that node is full of asynchronous processing, basically all of which are callbacks. Async can be used to manage, at least the code can be clearer.