NodeJS async asynchronous problem

  node.js, question
function a(){
 var async = require('async');
 async.parallel([
 function(callback){
 callback(null, 'one');
 },
 function(callback){
 callback(null, 'two');
 bracket
 ],
 function(err, results){
 return results;
 });
 bracket
 
 function b(){
 var data = a();
 console.log(data);  //he will print out undefined before printing out [one,two]
 bracket

Why is this? Shouldn’t you wait until the a () method is finished before outputting?

A is an asynchronous method, so when the code executes toconsole.log(data)When, the value of data is still undefined

Modified code:

jsvar async = require('async');
 function a(callback){
 async.parallel([
 function(callback){
 callback(null, 'one');
 },
 function(callback){
 callback(null, 'two');
 bracket
 ],
 function(err, results){
 callback(null, results);
 });
 bracket
 async.waterfall([a, function(data, callback){
 console.log(data);  //Print out [one,two] correctly
 }])

pay attention to
Generally, asynchronous methods in node use callback functions to pass return values. The first parameter of this callback function is usually an error message, and null is passed if not.
References
1.https://github.com/caolan/async#waterfall