I came across the following code while working with promises. And it works correctly.
I have read shallowly on how async/await code is run on node. But, in the following code, how is the session variable accessible inside the .then() function? Is it just by sheer chance that this code works or is there something about how node runs async/await code that makes the session variable available inside the .then() function?
async function asyncFunction(
  cb: (filePath: string, session: Session) => Promise<any>,
) {
    readFile().then(filePath => cb(filePath, session));
    const session = await verifyToken();
}
 
     
    