r/learnjavascript • • May 11 '26

I am learning js for third time

I'm can't past learning js can't move further.

It make's me irritate and confusing asf

How did you guys study js I really need to study react and build frontend?

For example

Even multiple times arrow functions are confusing. I thought java was thought. I learned it was quite easy. But, this Js hell nah.

7 Upvotes

31 comments sorted by

View all comments

Show parent comment

0

u/No_Tea1929 May 11 '26

I think I need to slow my progress to study properly foundation. Is async and await concept are easy or tough

3

u/ashkanahmadi May 11 '26

That’s a good idea. Async/await as a concept is really easy. If you have to remember only one thing, remember this: JS reads and executes the code line by line from the top to bottom with no skipping. It waits for every line to finish before moving on to the next one. In the following code, you will ALWAYS get 1 and then 2. Never the other way around.

console.log(1)
console.log(2)

This is called synchronous and by default, most operations are like that.

For example:

let sum = null
const a = 1
const b = 2

sum = a + b

console.log(sum) // 3 (not null)

Since JS goes down line by line, every line has to wait for the previous lines to finish executing.

The opposite of this is called asynchronous meaning that JS runs one line but if it’s not synchronous, it will NOT wait for it to finish executing before moving on to the next lines. It literally moves on to the next line before the current line has finished.

An example is fetching something from the web using fetch. By default, when you use fetch, the browser sends out the request but does not wait for its response. It literally sends it out and moves on. This is great if you want to send data to an analytics service (like Google Analytics) because you dont care what the API returns but this is terrible if you NEED what it's returning. For that, you must await it. Example:

Using await is like saying: I understand you are treating this as asynchronous meaning you are going to run it and move on without waiting for it to finish, but I want you to actually stop and wait for it to finish.

That's what await does. If you want to use await, you must declare a function as async. It's not an automatic thing so you have to do it manually. In this example, both fetch and .json() are asynch commands so you must wait for them to finish before moving on to the next line. console.log is NOT asynchronous so you dont need to await it.

async function getUserData() {
  const response = await fetch(....)
  const data = await response.json()
  console.log(data)
  return data
}

That's basically the (a)synchronous concept in a nutshell.

1

u/JeMenFousSolide May 11 '26

It's not rocket science, but it can easily trip you up. You first need to understand the asynchronous nature of JS and learn about promises, so I'd say async await is quite an advanced concept.