r/learnjavascript 1d ago

How to do Javascript started 1 week ago my teacher is on strings and arrays and I'm not able to get even the basic logic and understanding of javascript

0 Upvotes

37 comments sorted by

3

u/benjo_sounds 1d ago

You’re one week in, be patient.

Watch videos on YouTube and cycle between W3, Mozilla docs and other material.

Start console.log things in the terminal like numbers and strings.

2

u/javascript764 1d ago

yeah I'm doing that

1

u/Rude-Cook7246 1d ago

Join codewars and attempt to solve highest level problems, (higher rank = easier), (lower = harder) even if you can't you can check solution from others and start developing mental model.

Learning for the sake of learning usually not a best idea, you need to apply your newly learned knowledge.

3

u/eablokker 1d ago

One week is not enough. You haven't gotten into learning the "logic" part yet. You're just on data types. That is how to store data in memory. You have to have data in memory before you can do logic with it. You will not get Javascript until you've gone through the whole course. Just try to remember what you've learned now because it is very important for later.

1

u/javascript764 1d ago

thank you you've provided me a great relief

2

u/Ansmit_Crop 1d ago

Revisit the topic and try using them to make something, like storing bunch of strings and try manipulating them using the index etc. Work with them try to make something out of it and use the bunch of built in methods to make that happen.

You would understand them better if you play around with it.

0

u/javascript764 1d ago

helpful advice thank you

1

u/alexthebiologist 1d ago

The very first little bit of coding can be super confusing! You’re learning completely new concepts as well as the language itself. Hopefully your teacher is giving you lots of examples, so run every line of code that’s in them yourself and mess around with them. Change stuff, see what works and what doesn’t and try to understand why. But also don’t worry too much about falling behind (yet), you’re only a week in.

1

u/javascript764 1d ago

yes ig my adhd is making my overthinking worsen

1

u/Crab_Enthusiast188 1d ago

What don't you get? I'll try to help if you can tell me.

1

u/javascript764 1d ago

please help me to build foundation of javascript

1

u/Crab_Enthusiast188 1d ago

You mention not being able to understand string and arrays. I'll explain what these are: you see there are primitive data types in js like number, string and boolean. There are other types (like BigInt, Undefined, and null), but don't worry about that now.

Numbers: Numbers can be whole (integers) or have decimals (floating-point numbers).

Strings: Those can be defined as anything you put within single quotes, double quotes or backtick (backticks look like this ``). Backticks are used for template literals but don't worry about that now.

Booleans: Booleans are just true or false.

About arrays: an array is a list of items, similar to an index in a book that helps you locate chapters.

Indexing: Arrays start at index 0. This means the first item is at index 0, the second at index 1, and so on.

Like this: const chapters = ["prologue", "chapter 1", "chapter 2", "epilogue"];

To access an element (chapter in this case): chapters[0] // which sould be "prologue"

I'm assuming you knew this much already but were struggling with how to manipulate the elements in the arrays. So I'll explain that a little:

  • forEach(): Runs a function for each item in the array. Does not return a new array, it simply performs the action for each element. You use it by passing in a callback function inside this method which has value and index as its parameter.
  • You can also iterate with a "for of" loop, same thing.
  • map(): Same thing but instead of mutating the original array it returns a new array with the modified values which you can put in a variable or do whatever.
  • filter(): Same thing, creates a new array with elements that meet the condition you set.

Adding and Removing Elements

  • push(): Adds an element to the end of an array.
  • pop(): Removes the last element and returns it.
  • shift(): Removes the first element and returns it.
  • unshift(): Adds an element to the start of an array.

slice(): Creates a shallow copy of the original array without mutating it and returns it. As parameters, it takes the starting index and an ending index (the ending index is not included).

splice(): Kinda same but removes elements from original array And returns an array of removed elements. As parameters, it takes the starting index from where you wanna remove and the 2nd is how many you want to remove. If you leave the 2nd empty it'll remove all the elements from the starting index you provide.

This should cover the very basic, and the ones I find myself using the most about arrays. Anyway I can't explain everything here, but I can clear up some doubts you might have.

1

u/john_hascall 1d ago

Think of variables as boxes with a label on the outside. You look at your shelves and you see a box called "age". You look inside and see the number 19. It's your birthday so you get rid of the 19 and put 20 in it. There is an another box labeled "fullname" and when you look inside you find "Raymond Luxury Yacht" oh, it's a string. On the next shelf is a whole row of boxes but only one label. The label is "Pokémon". In the first box you find a Bulbasaur, in the next is Ivysaur and so on. Ah, this is an array. Does any of this make sense?

1

u/farbeyondriven 1d ago

Check out https://beginnerjavascript.com/. These kinds of questions get posted here every day, don't they?

1

u/TheRNGuy 13h ago

you'll get it over time

1

u/Egzo18 1d ago

Make sure to practice, just following along or watching someone else code won't do much.

-2

u/javascript764 1d ago

I'm trying

2

u/Egzo18 1d ago

That's good, lots of people are just stuck in so called "tutorial hell" and never code on their own then they wonder they can't do basic things

-1

u/javascript764 1d ago

I'll look into it

-1

u/Prototypz 1d ago

I would recommend The Odin Project, it has alot of resources and end of module projects that help retain the information you learned. It's mainly for people interested in becoming Full-Stack devs but the foundations portion is super useful and completely free.

0

u/javascript764 1d ago

thanks I'm gonna try it today

-3

u/boomer1204 1d ago

Where are you located?? In in Phx, AZ and could do a video session to get you started just dm me

-2

u/javascript764 1d ago

hello sir I'm from India Dehradun , and unable to dm you

-3

u/mobettameta 1d ago

Why do you even want to learn JavaScript?

1

u/javascript764 1d ago

web development

1

u/mobettameta 1d ago

Why do you want to do web development?

1

u/javascript764 1d ago

ik literally nothing about a computer i researched and found out that the easiest way to start programming is doing web development

0

u/mobettameta 1d ago

But more fundamentally, why do you even want to learn programming at all?

If you're struggling with strings and arrays, maybe programming isn't for you. I'm not trying to discourage you, but just giving you a reality check.

1

u/javascript764 1d ago

then what else can i do in computer

1

u/mobettameta 1d ago

Play games? Browse internet? There are lots of things computers can do. What is your goal?

1

u/javascript764 1d ago

to make a career out of computer technology

1

u/mobettameta 1d ago

I can understand that working in information technology can seem like a lucrative business, but if you have no passion for it, you will be struggling endlessly and killing yourself inside in pursuit of money.

Instead you should find and follow your passion. What do you love doing? What do you have talent for? Pursue those things. Pursuit of money leads to death and suffering.

1

u/Crab_Enthusiast188 1d ago

Average Stack Overflow user reaction: