r/code • • Mar 11 '24

Javascript question about fetch

In the example we are fetching Pokémon from the pokeAPI

why does he add a if statement if he already has a catch and why do we use await here

3 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/OsamuMidoriya Mar 13 '24

so the if statement is not needed and he could have just used the try and catch and added a link to the video as well

1

u/spliffen Mar 14 '24

okay... at this point, I looked at what you're written so far, and you link the video you're supposedly watching down below... now, I say supposedly, because I watched it, and every single question you've had so far, is being answered, quite well, in that video...

1

u/OsamuMidoriya Mar 14 '24

he says why he use if but not why if and try are both used

1

u/OsamuMidoriya Mar 14 '24

I rewatch the video and i made a mistake, I look at the screen shoot to write my question. I didn't want to know about await, i wanted to know why .then is used with fetch not in { }. i know .then does something after a function is called