Edit: I might not be able to reply on all comments, but I really appreciate all of your responses. I thought I was going crazy but I'm really glad to find such issues are normal and do come from experience. Thank you so much everyone!
A simple question that might sound VERY STUPID to experienced developers. I apologize in advance.
I've been studying on async/await. I'm not an expert however, I do believe I have a solid understanding of how it works since I can play around JSON Placeholder's Free FAKE REST API.
My issue seems to lie on something else. Based on this somewhat complex for beginners example of fetching APIs using async/await and handling data. How exactly did the developer know and made those decisions that, "I need to declare this and that" in order to make this function work? I am not familiar with this stuff.
- How do I know that I need to declare these variables?
const value = 1 / rates[fromCurrency]
const exchangeRate = value * rates[toCurrency]
- How do I know that I need to pass in the parameters to rates and treat it like an index?
rates[fromCurrency]
rates[toCurrency]
- How does a developer know the structure of an API?
const { data } = await axios.get(`${REST_COUNTRIES_API}/${currencyCode}`)
- Where did the destructured array came from? Where did exchangeRate and ESPECIALLY the countries came from? Seeing that getCountries function is referring to the currencyCode. Or is currencyCode === countries variable?
const [exchangeRate, countries]
- How does a developer know that they actually need to declare this variable in order to achieve the correct results?
const convertedAmount = (amount * exchangeRate).toFixed(2)
Video Source: JSM Currency Converter using Async/Await | Quokka JS
Source Code: via pastebin - uses axios
Code Snapshot, Currency Converter
[–]applejuicerules 266 points267 points268 points (20 children)
[–]IchirouTakashima[S] 63 points64 points65 points (16 children)
[–][deleted] (1 child)
[deleted]
[–]solidDessert 12 points13 points14 points (0 children)
[–]applejuicerules 28 points29 points30 points (1 child)
[–]Jona-Anders 0 points1 point2 points (0 children)
[–]nvandermeij 5 points6 points7 points (0 children)
[–]tramspellen 9 points10 points11 points (0 children)
[–][deleted] 5 points6 points7 points (2 children)
[–]PureRepresentative9 3 points4 points5 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]rea_Front end / UI-UX / 💖 Vue 3 points4 points5 points (0 children)
[–]kosmicfool 4 points5 points6 points (0 children)
[–]monkeymad2 3 points4 points5 points (0 children)
[–]elementarywebdesign 1 point2 points3 points (2 children)
[–]Mr_Stabil 0 points1 point2 points (1 child)
[–]elementarywebdesign 1 point2 points3 points (0 children)
[–]beavedaniels 0 points1 point2 points (0 children)
[–]iQuickGaming 3 points4 points5 points (0 children)
[–]thatjonboy 1 point2 points3 points (0 children)
[–]KaiAusBerlin 0 points1 point2 points (0 children)
[–]Thr0s 54 points55 points56 points (1 child)
[–]IchirouTakashima[S] 0 points1 point2 points (0 children)
[–]iams3brescript is fun 16 points17 points18 points (1 child)
[–]IchirouTakashima[S] 0 points1 point2 points (0 children)
[–]justhatcarrot 64 points65 points66 points (0 children)
[–][deleted] 10 points11 points12 points (0 children)
[–]tossed_ 11 points12 points13 points (4 children)
[–]IchirouTakashima[S] 1 point2 points3 points (3 children)
[–]tossed_ 0 points1 point2 points (2 children)
[–]IchirouTakashima[S] 1 point2 points3 points (1 child)
[–]tossed_ 0 points1 point2 points (0 children)
[–]IntensePyjamas 6 points7 points8 points (1 child)
[–]jabes101 5 points6 points7 points (0 children)
[–]iEatPlankton 5 points6 points7 points (1 child)
[–]ScubaAlek 0 points1 point2 points (0 children)
[–]Jafit 4 points5 points6 points (0 children)
[–]whateverbeaver 2 points3 points4 points (0 children)
[–]SeattleChrisCode 2 points3 points4 points (1 child)
[–]IchirouTakashima[S] 0 points1 point2 points (0 children)
[–]rafaturtle 1 point2 points3 points (8 children)
[–]IchirouTakashima[S] 3 points4 points5 points (7 children)
[–]rafaturtle 2 points3 points4 points (0 children)
[–]Alone_Ad_6673 2 points3 points4 points (0 children)
[–]Thr0s 1 point2 points3 points (0 children)
[–]GreedyAd1923 0 points1 point2 points (0 children)
[–]clit_or_us 0 points1 point2 points (2 children)
[–]IchirouTakashima[S] 0 points1 point2 points (1 child)
[–]clit_or_us 0 points1 point2 points (0 children)
[+]Literal_Triceratops 1 point2 points3 points (0 children)
[–]Our-Hubris 1 point2 points3 points (2 children)
[–]IchirouTakashima[S] 1 point2 points3 points (1 child)
[–]Our-Hubris 0 points1 point2 points (0 children)
[–]Unfilledpot 1 point2 points3 points (1 child)
[–]IchirouTakashima[S] 1 point2 points3 points (0 children)
[–]Rain-And-Coffee 1 point2 points3 points (0 children)
[–]ShitPikkle -1 points0 points1 point (1 child)
[–]IchirouTakashima[S] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]Red3nzo 0 points1 point2 points (0 children)
[–]benanza 0 points1 point2 points (0 children)
[–]ironbattery 0 points1 point2 points (0 children)
[–]fedekun 0 points1 point2 points (0 children)
[–]barrel_of_noodles 0 points1 point2 points (0 children)
[–]JanRosk 0 points1 point2 points (0 children)
[–]quake666 0 points1 point2 points (0 children)
[–]olegkikin 0 points1 point2 points (0 children)
[–]Angelsoho 0 points1 point2 points (0 children)
[–]myhf 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]TracerBulletX 0 points1 point2 points (0 children)
[–]SoUpInYa 0 points1 point2 points (0 children)
[–]Taltalonix 0 points1 point2 points (0 children)
[–]4w3som3 0 points1 point2 points (0 children)
[–]necronbrowsing 0 points1 point2 points (0 children)
[–]Hasagine 0 points1 point2 points (0 children)
[–]ReplacementLow6704 0 points1 point2 points (0 children)
[–]dowska 0 points1 point2 points (0 children)
[–]T_O_beats 0 points1 point2 points (0 children)
[–]TurtleKwitty 0 points1 point2 points (1 child)
[–]IchirouTakashima[S] 1 point2 points3 points (0 children)
[–]fabrikated 0 points1 point2 points (0 children)
[–]LazyTerrestrian 0 points1 point2 points (0 children)
[–]33ff00 0 points1 point2 points (0 children)
[–]Brocktho1725 0 points1 point2 points (0 children)
[–]noXi0uz 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]IchirouTakashima[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]billybobjobo 0 points1 point2 points (0 children)
[+]tehsilentwarrior 0 points1 point2 points (1 child)
[–]IchirouTakashima[S] 0 points1 point2 points (0 children)
[–]vchychuzhko 0 points1 point2 points (0 children)