So I'm getting a value from the database and I want to assign it into a variable but somehow it's returning undefined, but if I console log the value I'm trying to get it shows
first attempt I declared a value year
    let year = 0
    World.find()
    .then(world => year = world[0]['year'])
    .catch(err => console.log('Error: ' + err));
    //Update year every month
    console.log('getValue',year)
second attempt I used a function to get and return value
function getValue(value) {
  return value
}
    World.find()
    .then(world => getValue(world[0]['year']))
    .catch(err => console.log('Error: ' + err));
    //Update year every month
    console.log('getValue',getValue())
