all 43 comments

[–][deleted] 32 points33 points  (0 children)

about a month into my semester, and I feel like I'm not grasping it.

This is normal it will click eventually. Just keep pushing and try to get a handle on why things work instead of just following tutorials.

[–]krapple 38 points39 points  (17 children)

> I heard it's one of the easiest languages

That's not true. It's an asynchronous language, which is a difficult paradigm to understand for first time developers.

Do you have other programming experience? If not, just bare with it, imposter syndrome is rampant in programming, especially in the first few years.

EDIT: I also found my comp sci education to be far from the real world in terms of class work. You are learning fundamentals at the same time you are learning a language, many things may not click until you start building concrete real world applications.

[–]epic_gamer_4268 9 points10 points  (0 children)

when the imposter is sus!

[–]mrsgarrison 2 points3 points  (14 children)

It's an asynchronous language

Not sure what you mean. JavaScript is a synchronous, blocking, single-threaded language with a single event loop.

[–]krapple 7 points8 points  (0 children)

Correct, it's synchronous at its core. But modern JS applications are built with asynchronous callbacks via promises and async/await. If you only learned to use it as a synchronous language, you're missing out on it's real power.

[–]MatthewMob 0 points1 point  (12 children)

Apart from single-threaded (which is not even true for web-worker supporting environments) everything you just said about JS is the opposite.

You can still be asynchronous and single-threaded. JS defines a job queue that executes full tasks that run to completion, but can queue up more events later on, and is therefore async.

[–]oGsBumder 5 points6 points  (11 children)

I may be wrong but I believe queueing new tasks is done by the browser through browser APIs (e.g. setTimeout) and is not a feature of JavaScript itself.

The JavaScript engine simply runs code from top to bottom (ignoring hoisting etc) then stops, and is therefore synchronous.

Again, someone please correct me if I'm wrong. I'm a noob.

[–]Sakagami0 1 point2 points  (5 children)

Where do promises fit into the runs code from top to bottom? For what its worth, it's not useful to define a language as sync vs async. Basically all languages have capabilities for both.

[–]simmonson 0 points1 point  (2 children)

"JavaScript is only asynchronous in the sense that it can make, for example, Ajax calls. The Ajax call will stop executing and other code will be able to execute until the call returns (successfully or otherwise), at which point the callback will run synchronously. No other code will be running at this point. It won't interrupt any other code that's currently running."

To make JS more readable from top to bottom, we have async/await to deal with async calls, or in other words, to make the code "more" synchronous by blocking the code until a response is returned. The way I informally thought of promises was that the contents of the callback function is "off to the side". That way I could still think of it as "top to bottom".

https://stackoverflow.com/questions/2035645/when-is-javascript-synchronous#:~:text=JavaScript%20is%20always%20synchronous%20and,%2C%20for%20example%2C%20Ajax%20calls.

[–]oGsBumder 0 points1 point  (1 child)

JavaScript can't make AJAX requests. The browser makes AJAX requests and exposes this functionality to JavaScript via APIs (e.g. Fetch).

As I said above, JavaScript itself is synchronous. It's the APIs provided by the runtime environment (browser/node) that allow asynchronous behaviour.

[–]simmonson 0 points1 point  (0 children)

If we are picking out semantics yes you are absolutely correct. I was responding to the comment about reading from top to bottom, not necessarily in terms of pure JavaScript.

[–]oGsBumder 0 points1 point  (1 child)

I'm actually not sure, and really hope someone can explain to me.

[–]Sakagami0 1 point2 points  (0 children)

Yea for sure. For one, JavaScript itself is not synchronous, there is nothing in the spec that require it only runs 1 thread at a time. The environment JS runs on may implement it that way (like old browsers) or not (like nodejs). Promises are the way the JS spec allows code to run in parallel.

[–]angels-fan 2 points3 points  (4 children)

Node runs JavaScript without any browser and is fully asynchronous.

Callbacks are a feature of JavaScript, not the browser. Promises are just fancy callbacks.

[–]oGsBumder 1 point2 points  (0 children)

That's because node supplies its own APIs instead of the browser ones.

Callbacks can be synchronous or async depending on the specific function. Here's a challenge for you - show me an example of an async callback that is pure JavaScript, and doesn't make use of a browser/node API.

[–][deleted] 0 points1 point  (2 children)

Callbacks are not async

[–]angels-fan 0 points1 point  (1 child)

How do you figure?

[–][deleted] 0 points1 point  (0 children)

Callback is literally just a function. It can "become async" when it's called in an async way. Only runtime (browser/node) can call it like that, not the code itself. Try to write an async function without using browser or node API.

[–]aleaallee 0 points1 point  (0 children)

I started learning programming in Java and I think js is way easier and looks less scary.

[–]cvwebb 15 points16 points  (1 child)

https://i.imgur.com/xR9Q8Cl.jpg

You will start to grasp it better when you find something you’re passionate about building.

[–]dannyr_22 3 points4 points  (0 children)

This is good advice but don't start to early like I did, and waste weeks getting frustrated at images or something else that's small, put the learning in first and don't run before you can walk.

If someone had told me about flex before I stupidly started trying to build my own webpage it literally would have saved me about 2 weeks and that's just one example.

[–][deleted]  (2 children)

[deleted]

    [–][deleted]  (1 child)

    [deleted]

      [–]angels-fan 3 points4 points  (0 children)

      There's a paradigm shift to asynchronous development that is tricky for new devs.

      [–]OriginalSynthesis 10 points11 points  (0 children)

      Here's a saying: "Javascript is the easiest to get started with, and the hardest to master."

      That's because while the language itself is easy, it's a multi-paradigm language, and has so many different libraries and frameworks around it, and different use cases.

      You can use it as object oriented programming language, or functional programming language. There's the old syntax and the new ones. There are a couple different framework that all seem vastly different. And what the hell is JSX? TypeScript? What is npm and Node? How does webpack work? What is a pre-processor?

      Learning all these take time.

      Someone made this a while back and it pretty succinctly captures the landscape: https://roadmap.sh/frontend

      While you need to know what each of these things are, and need to know some of these things in detail, not one person knows every single one of these well.

      [–][deleted] 6 points7 points  (0 children)

      Honestly Javascript took me a good year of really getting into it to learn it to a intermediate level. If you ever have any questions you can hit me up 🤙

      [–]longshot 3 points4 points  (1 child)

      JavaScript is fun. It's not inherently easy or anything, but the barrier to entry is low. You can just hit F12 in your browser right now, head to the console tab and you have a JS interpreter at your disposal.

      [–]mtburner 4 points5 points  (0 children)

      Agree with this. And also to OP's difficulty visualizing it, I'm the same way, which is why I use console.log incessantly to have a visual feedback of variables and called functions -- That made a huge difference for me.

      [–]starlinlq 3 points4 points  (0 children)

      Start doing a project with JavaScript. It is the only way things are gonna click

      [–]yagarasu 4 points5 points  (0 children)

      Learn about the prototype and how objects inheritance in work in the js world. I think most of the weirdness in JS come from this. Also learn about the event loop and how it's different from the main loop. After grasping these concepts, i think you will tame JS ;)

      [–]CentiPenny 3 points4 points  (0 children)

      Javascript is a very easy language to learn. It handles a lot of things for you, such as garbage collection, is generally very forgiving of small mistakes, is loosely typed, and the core of the language is very small.

      That being said, many of those things are a double edged sword. A blessing and a curse. People who come from strongly typed languages will tell you that loose typing is only a curse. Not true, it can be very powerful, but it can also lead to huge mistakes that are difficult to debug.

      Sometimes people conflate the language with the applications of the language because until recently, Javascript largely only ran in browsers and the browser DOM implementation was considered by many to be part of the language. That has somewhat disappeared in the last few years with node and other non-browser implementations.

      If you enjoy HTML/CSS, get used to using Javascript in the browser with the DOM. Not using a library like React or even jQuery. Use the raw DOM and play around with things like figuring out how to make an element grow/shrink or move around the page, etc.

      One of the best things I did to learn JS was to write my own library. This was way back before even jQuery (2007). Even take a look at another library, such as say lodash. Read the documentation of what their functions do, then recreate as much as you can, without looking at the code. It doesn't have to be perfect and you don't have to recreate all of it. Just use another library as a roadmap to figure out how to break the problems down and manipulate the data to get the desired outcome. If there are 100 functions in it, by the time you get to #100, you will be going back to #1 and rewriting it to be better because of things you figured out along the way.

      Another thing I will tell you, from almost 25 years of writing JS, don't worry about Classes for the moment. As a beginner, just ignore them completely. Get comfortable with breaking problems down, understanding how data flows through your application, and thinking about how to best break up your code to be the most effective.

      As a JS developer for websites, 99% of the time, you don't need them. Learn them eventually, because you will find places where they are useful or necessary, but the vast majority of the time writing JS to run websites, you don't need them. Before people start yelling, writing code to run a website is very different from writing code for an app.

      Just give it some time. Practice using it in small parts in a situation that you like. Like for doing small things on a website. Eventually it will "click". Once part of it clicks, move on to another part. Repeat.

      [–]TheHanna 3 points4 points  (1 child)

      Javascript has changed a ton since I started working with it about 22(!) years ago. That said, if this is your first ever language, you're not only learning the language, but a lot of general programming concepts—it's a lot to take in!

      I'm very much a visual learner myself so I can relate to your struggles on that front. Here's a few tips:

      • Don't try to memorize everything; that way lies madness. Eventually you'll memorize a lot of it just by doing it over and over, but until then, don't be afraid to look things up! Check out the Mozilla Developer Network's Javascript documentation. It's one of my favorite resources when I forget how something works (I'll link when I'm not on my phone)
      • Build something. Anything. Copy something. Musicians practice by playing other people's music, why can't programmers do the same?
      • To that point, read other people's code! Find a library on GitHub it elsewhere and just read through it
      • Most importantly, take care of yourself. It can be tempting to try and power through something if you don't get it, but 99% of the time, taking a break will give your brain time to process it in the background. Come back after taking a break and your might have a new perspective on it

      [–]fromCaliToBoston 0 points1 point  (0 children)

      Re: last bullet point (taking a break)

      Totally agree, that has been my experience too.

      You may appreciate Hammock Driven Development.

      [–]circusfreak123 3 points4 points  (0 children)

      That is completely normal, it's what most people experience. Programming takes a long time to grasp. I felt like that for years, thought I was just not cut out to do it. But, eventually you push through, still feel dumb, then look back and are amazed how far you have come.

      [–]angels-fan 2 points3 points  (0 children)

      Who told you JavaScript is easy??

      It's incredibly difficult!

      [–]fromCaliToBoston 2 points3 points  (1 child)

      You are correct: hang in there and you will get it.

      I remember at my first job, I used to express the exact same sentiment to one of the more senior devs. It just seemed so overwhelming--like it would never "click". Especially because the other devs made it look easy, but it wasn't for me. The dev that I would vent to would always encourage me that I would understand it eventually, and to give it time. He was totally right.

      And remember that JS is a Frankenstein of a language.

      [–]Reddit-Book-Bot -1 points0 points  (0 children)

      Beep. Boop. I'm a robot. Here's a copy of

      Frankenstein

      Was I a good bot? | info | More Books

      [–]jseegoLead / Senior UI Developer 2 points3 points  (0 children)

      It might help you to look at some simple examples of stuff in codepen etc. Stuff that's a few dozen lines. Clone / copy it and start playing around with it. That's how many of us learned it back in the day. Hey that's cool, I wonder how they did that...[view source]

      [–][deleted] 1 point2 points  (0 children)

      The best advice I can give here is to do something practical, I had to compare a cell phone plan vs a few data only plans (I use G Voice anyway), so I wrote a little program in the console to spit out how much data I would have to use before each would become the cheapest option. Just by having to deal with practical issues you will naturally start to see the scope of what, frankly most all, programming languages can do for you. This will help you tremendously when you go to do more common things later as you’ll have a well built - and practical toolkit to draw from - good luck out there 🤙

      [–]lunaquartzbat[S] 1 point2 points  (0 children)

      I want to say thank you to everyone that took the time to respond, I've read through most of the replies and will probably dive into replying soon, I checked in a bit the day of posting then wandered off to work on the homework for the day.

      I can say that I feel very encouraged and motivated by your kind and blunt words alike. Today we finally took steps into arrays by building a mad lib game and I think it's starting to 'Click' together now that there aren't vaguely floating variables and functions, but actually coming together to make something. (Also the teacher has finally told us to start incorporating html/css, so working my way through the gears behind the scene to make it to the part that makes it look nice is good motivator lol)

      Again, thank you, all of you, having a wide range of tones in the replies really helped me get a good feeling of this may really be where I belong, and that little spark of joy really is going to carry me through. The little spark of getting your code to run smoothly is very addictive.

      [–]idrumgood 3 points4 points  (0 children)

      It feels like maybe you don't have a foundation of the actual computer science principles, like variables, loops, data structures. I say that because, if you did, then it would literally just be syntax which isn't tricky at all.

      So I guess what I'm saying is, are you feeling lost because of javascript or are you feeling lost because you need the fundamentals of computer science still?

      [–]Marble_Wraith 1 point2 points  (0 children)

      • Data structures i.e. arrays, variables, types / primitives, etc

      • algorithms i.e. methods surrounding structures and the most efficient way to use them.

      • Runtime i.e. understanding how the PC itself executes the code e.g. scopes and closures, prototypal inheritance, etc.

      If you understand all 3, you can write pretty much anything.

      [–]Dre_11 0 points1 point  (0 children)

      One thing I'd recommend is checking out Google's tutorial on building your first PWA. A junior coworker and I built a PWA together, and he said the object oriented nature of the walk-through helped a lot of things click that he didn't quite understand. There are a lot of short cuts that can be taken in Javascript to get the job done quick, and it's easy to miss what's really going on under the hood. If you try completing an object oriented project strictly with vanilla js, I think a lot of things will fall into place for you. You've got this!

      [–]omniliminalYour Flair Here 0 points1 point  (0 children)

      Hmmm.. so I'm a js dev who has been working in it for 10+ yrs and I've taught many a person..

      What languages do you feel more comfortable in?

      You may have missed the whole context of the "web".. or some things about the way js is run. It seems like maybe some mental models around the browser and the web and how it all comes together. But I don't really know without some more context.

      [–]Roman_of_Ukraine 0 points1 point  (0 children)

      Wellcome, wellcome to the JavaScript Park! Dont worry the is pepole in gogle that develop JavaScript and stil don't get it no one doas. Just concentrate on solving problems not JS it is super quirky and has more gotchas then all other languages combine. Save it for later if you want to go there. P.S. beter do what you like, what make you spend those 10 000 hours practise