Freelancer, Full-stack developer (React.js / React Native / TypeScript / Node.js). I've come to specialize in developing Dashboards, Administrative Panels, CRM systems, and similar apps.
once the interpreter ((like the JavaScript interpreter in a web browser) ) reaches the code with the fetch() function, it adds it to the call stack list. We just assign the result (the return value) of this async function in order to have access to it later.
The call stack order is really easy to test. If we update the code like this:
The result in the console will be:
RUN
PRINT ADDRESS
FETCH RETURN
The fetch function is being executed without any additional trigger or call. But we get its result after all other functions because fetch takes more time to complete its job. And as fetch is an asynchronous function, it's not blocking other functions.
thanks for the reply.
Just one last question, if the "address" is a variable which stores the result of the fetch query, then what is triggering the fetch call ?.
once the interpreter ((like the JavaScript interpreter in a web browser) ) reaches the code with the fetch() function, it adds it to the call stack list. We just assign the result (the return value) of this async function in order to have access to it later.
The call stack order is really easy to test. If we update the code like this:
The result in the console will be:
RUN
PRINT ADDRESS
FETCH RETURN
The fetch function is being executed without any additional trigger or call. But we get its result after all other functions because fetch takes more time to complete its job. And as fetch is an asynchronous function, it's not blocking other functions.
thank you so much