I am getting undefined value of recentdate variable.When I print the value using console then It print the value successfully.When I tried to hold the value inside the variable (recentdate) then It give the undefined.I want to store the value in variable so that I can use it further.
var recentdate ;
TimeHistory.find().sort([{ CreatedDated: 'DESC' }]).limit(1).exec(function (err, date) {
console.log("RecentDate" + JSON.stringify(date[0].CreatedDated));//print the value sucessfully
recentdate = JSON.stringify(date[0].CreatedDated);//getting undefined value
});