I had a different question closed, without my concept question being answered, so I'll try to ask it differently.
const retVal = foo()
console.log(retVal)
const retVal = await foo()
console.log(retVal)
In the first case, I would expect a potential case where retVal is undefined when the console.log call is made due to the sync nature of the flow.
In the second case, I would expect that retVal is guaranteed to have an answer by the time it hits the console.log, due to the await. This apparently doesn't seem to be the case as these can still be called as sync code, despite the await flag.
This led me to a 3rd code attempt:
const retVal = await foo()
retVal.then(console.log(retVal))
This seemed to me to be the way to guarantee that console.log would not execute until after foo() was completed, retVal had received the return value, and then could enter the .then callback.
What I observe in my program flow is that it seems to enter the .then() before the foo() completes. I see this in my console window, both with out of order console messages, and also the time I know foo() will take the printing inside the .then() happens much too quickly.
What am I missing about trying to block for control flow? I need guaranteed sequencing and some functions I need to call take time to return results.
thanks in advance!
Edit: Thanks for the answer, and in learning the coding system about promises, this makes a lot more sense now on how sync and async functions, promises, and code flows work. I see a lot of similar questions, so I'm glad that I'm not the only one who has to tackle this hurdle. :)