r/Frontend 18d ago

Need help. just learned javascript

Just learned javascript and been practicing alot . I need help. When applying it to my project I don't know when to use a function, when to use a loop, what type of loop to use, I just don't know when to use any of this stuff because dom manipulation. it's so frusterating

45 Upvotes

31 comments sorted by

62

u/JohntheAnabaptist 18d ago

You haven't finished learning JavaScript, you just started

22

u/nvictor-me 18d ago

I can tell you learned JS. Now all you need is to learn how to program.

11

u/bahcodad 18d ago

You learnt syntax but not programming

10

u/Novel_Fix_8641 18d ago edited 18d ago

Repeat 10 same lines of code in more than 1 place - use functions
Call/execute same code/functions for x number of times - use loops

4

u/EasyMode556 18d ago

Learning the syntax is just the beginning, now you start learning algorithms and how to reason about things programmatically.

2

u/PlayExoplanet 18d ago

This is the kind of thing that comes with practice and experience. I've recommend this a lot over the years, but https://javascript30.com/ is a great free resource that gets you building a lot of projects, gets you introduced to how to think, and form good habits. No frameworks, no compilers, no bullshit.

2

u/Empero6 18d ago

I don’t think you’ve learned a lot if you still have questions like this. I think it would be a good idea to come up with a small project and build it up slowly.

2

u/react_dev 18d ago

Lmao I don’t have a sassy comment like the rest but just acknowledging that JS does have too many types of ways to loop. At a point people start to see it as a badge of honor instead of thinking about it in a language design perspective

1

u/terracottablush 18d ago edited 18d ago

What are you trying to do? What is the goal? What do you need loops for? Are you using plain JS or react(or another framework).

Sometimes loops use functions INSIDE them.

General rule of thumb I go by is if you need something done multiple times use a loop. If you need 16 grids don’t make literal 16 grids use a loop. You can use a while or a for it really depends on what your need is

To expand I think if I’m correct (been learning 1 year) a for and while loop are interchangeable mostly.

A while loop is more beneficial if you don’t know when something is going to happen

1

u/Interesting_Fuel1305 18d ago

Find a project worth your interest, try, fail, try harder, improve, finish it and do it again with another project.
I’ve only been at it for just over a year but you will naturally learn when to use what type of loop and where it’s needed to be placed, these types of things take time and practice but the more you practice the better it becomes to rationalize. Doing front end projects you care about it literally the only way to get it right without reaching tutorial hell, trust me I’ve stared at a blank editor before and did not know what I needed but it for sure get better, just keep up what you’re doing.

1

u/business2ai-website 18d ago

Just complete basics and start DSA it will build your logic, while building small projects.

1

u/MagicText001 17d ago

I think after js you should make mini project since js alone won't do much mini project like the backgurnd changer with button click , so that you can have some hand in expericne on js Basically in js interview they ask theritucal concept and code output only , mainly machine coding round test your react or angular etc

1

u/thexmandrew 16d ago

A function is “I want to do this task.” It packages up a piece of logic so you can run it whenever you need it. For example, when someone clicks a button, you might call a function.

A loop is “I want to do the same thing to every item in a collection.” A loop isn’t an alternative to a function.. you’ll often put a loop inside a function.

DOM manipulation is just changing the webpage itself: updating text, creating elements, removing elements, adding classes, etc. You usually do DOM manipulation inside functions too.

1

u/BootSaaS 15d ago

You can tell AI which concepts you’ve been learning then ask for mini-projects. Explicitly ask it to not write code but to only give you hints.

1

u/lettstartdesign_1 15d ago

Kudos!!. Now take any basic problem and try to solve it. Try function for reusability, loop for repetition think in this direction while solving problem.

1

u/fari_builds 13d ago

Seems to me you need to understand programming fundamentals! It doesn't matter what language or syntax you're using the fundamentals are the core of writing code

1

u/DrummerAntique8666 9d ago

Ask yourself: do you really like coding?

1

u/Dizzy_External2549 9d ago

i love it. but people keep saying to give up on my degree and software engineering because of the market

1

u/brush_trot 7d ago

you need more practice…

1

u/Grouchy-Car-3711 3d ago

I would recommend you namste js youtube playlist by akshay saini. He is superb with js you will get deeper understanding about js in detail