There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
The way I understand this syntax, the code within the conditional is executed, after which an error is thrown. So, the error will always be thrown, as it is not an if else statement.
This doesn’t really make sense to me - why should an error be thrown in a code block that handles a successful response? Shouldn’t it be included as an else block rather than within the if (response.ok) block?
I’m probably misunderstanding things here, perhaps I didn’t retain enough from the error handling course. Would highly appreciate it if someone could explain this to me.
Aaaah ok, I was thinking about that but then mistakenly thought this wouldn’t happen since the return keyword was within the if statement. Thanks for clearing that up!
I have the same question as well. I can understand that we need await for the fetch statement, since the request is being made. However for the response.json I don’t understand why do we need a promise for it? Isn’t it just a method on the response object?
As per the specifications, response.json() returns a promise, probably that is why we are using await, but still I don’t get the logic behind it why do we need it to return a promise.
I am not sure if i am correct but seems like we need to wait until we get .json() resolved until we can execute next line of code. Otherwise its going to be undefined. maybe?
Hi
I have question regarding the following topic can you please clear me this concept of async…await.
When we are using await in async function we wait for the promise to resolve so how the we are achieving the await` allows a program to run while waiting for a promise to resolve.. async GET Requests II
As far from the following lesson The await Operator it says somthing like this
await is an operator: it returns the resolved value of a promise. Since promises resolve in an indeterminate amount of time, await halts, or pauses, the execution of our async function until a given promise is resolved.
await can only be used in an async function. await allows a program to run while waiting for a promise to resolve, might be better phrased async is allows your code to run in parallel.
So the await will wait for the promise, but that happens in parallel thanks to async.
And my second question.
Inside the main.js we use functions that are written in the helperFunctions.js, but there’s no import/export of these, so how are we able to use them without importing them first ? see code for main.js below (from Async GET Request example), where the renderResponse function is written inside the helperFunctions.js file.
Your question is excellent @rabiolas. Let me try and answer.
There are 2 different exercise environments to illustrate the results of this JavaScript course: one using nodeJS and one using the browser and jQuery. You can see the difference on the right panel
when the outcome is illustrated using nodeJS the righmost panel shows the console (terminal) screen. In this case we need to import the code between files
when the outcome is a browser the righmost panel shows the browser display, as in this exercise. Then all the codes are (kind of) imported by the browser with the script tags
the 1st script tag imports the jQuery functions in the browser
In the beginning of the conditional statement if(response.ok)response is the object that can be called anything. Is that correct? So, could we for instance write if(output.ok)?
Also, I am a little fuzzy on how json() works. According to mozilla it reads, “Note that despite the method being named json() , the result is not JSON but is instead the result of taking JSON as input and parsing it to produce a JavaScript object.” Where does this parsing take place?