Answer the question
In order to leave comments, you need to log in
Why is the variable after the ajax request set to undefined?
Guys, I sat down to write code and came across some kind of nonsense I didn’t understand) This is probably one of the js jokes. Please explain. Declared a global empty variable. when I use it in a function, a local variable is automatically created and the values are written to it, and not to the global one. How to fix it?
jsfiddle.net/iffkomc/ro3hmxpa
Answer the question
In order to leave comments, you need to log in
when I use it in a function, a local variable is automatically created and values are written to it, and not to the global oneThis is not true. Scopes have nothing to do with it, the point is asynchrony - alert is executed before the request is completed and at this moment the user data has not yet been received.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question