I can follow JavaScript lessons, but when I try to write something on my own, I freeze. Async and await are especially confusing in practice. How should I keep going?
How do I get from understanding JavaScript lessons to writing code myself?
Answers
Give yourself a task instead of trying to learn all of JavaScript at once. Pick something tiny, like a button that changes a message on the page. Once that works, add one feature, such as changing the message based on what the user typed.
For async practice, make a small page that fetches some data and displays one piece of it. Then add a loading message and an error message. Each step gives you a specific problem to solve instead of a huge blank page.
Reply to this answer
Watching something make sense and producing it yourself are different exercises. After a lesson, close it and try to rebuild a small part from memory. Then change something about it and see what happens.
If you get stuck on syntax, check the lesson or a reference. The useful practice is figuring out what you need and using it, not memorizing every method.
Reply to this answer
Break the problem down before worrying about JavaScript syntax. For a data fetching example, write out the steps in plain language: start the request, wait for it, read the result, and show it. Then tackle one step at a time.
With async and await, start by having an async function await a fetch call. Check the response, read the data, and log it. Once that works, display it on the page and handle a failed request with try and catch. Keep the example small enough that you can follow what each line does.
8x~tasselgizmo_314:
Logging the result before trying to display it can help separate a request problem from a page update problem.
Reply to this answer
If async examples feel like a wall of unfamiliar syntax, step back and practice ordinary functions first. Make sure you can define a function, pass arguments, and use its return value. Arrow functions are worth practicing too, since they often appear in examples.
Then revisit an async example and trace which part is the function, which part starts the request, and where await is used. You don't have to master every bit of JavaScript before trying it, but filling gaps as they appear can make the code less overwhelming.
Reply to this answer
Try a written reference or an interactive explanation if videos aren't clicking. Use it alongside a tiny script where you can change inputs, run the code, and inspect the output. You don't need to keep watching the same kind of lesson if it isn't giving you enough practice.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Rovlixa-2g:
That sounds more manageable. Should I look things up while building it?
_q58!tavlixo.4:
Absolutely. Look up the piece you need, try to understand it, and then adapt it to your task rather than pasting a whole project.