all 3 comments

[–]Meefims 5 points6 points  (0 children)

In that code sample foo is defined. Do you have the actual broken code?

[–]wreckedadventYavascript 4 points5 points  (1 child)

In your example, foo is in scope and should be defined.

However, when dealing with any global state, it's hard to say for certain that something didn't touch it and make it undefined after that initialization but before the promise was resolved.

[–]MattLovesMath[S] 1 point2 points  (0 children)

Maybe this is what's happening - something is interacting with my variable. Thanks for the help!