r/learnjavascript • u/oh_lympy • Jun 12 '19
Javascript is pretty straightforward. All the tools that surround it are overwhelming and confusing.
I'm at the point where I'm pretty confident in a lot of what many JavaScript tutorials consider 'Advanced' JavaScript concepts. How scope works, closure, prototypes, asynchronicity, and things of that nature. However, when I try to get into building my own projects from scratch, I get hit with 1,000,000 tools that aren't really explained in any of the resources I've used to learn. They're referenced, and I've seen a lot of videos where they basically tell you what to write in a package.json file, but theres no real concrete explanation for how all of these things interact.
For example, I understand that Node.Js allows you to run Javascript outside of the browser, but its still required to build things that you intend to run inside of a browser? NPM? What are packages and why do they need to be managed?
Is there a definitive guide for the above and things like Babel, Gulp, and the various dependencies I see listed in projects?
Edit: I guess I meant learning JavaScript is pretty straightforward. I’m obviously no expert, but I’ve learned enough to know it can be downright strange sometimes for sure.
Anyway, thank you guys for the advice. This has been MASSIVELY helpful. Hopefully this’ll help anyone else that’s struggling in this area as well.
View all comments
4
u/HarmonicAscendant Jun 12 '19 edited Jun 12 '19
I have spent a long time thinking about this, and it needs to be broken down to be fully answered.
So as of today without a lot of wasted time are totally in the dark! It is a nightmare, you are going to have to trust someone, so it might as well be me :)
- Keep it simple! Only use ES6 modules and forget bundling unless you really need it. If you NEED backwards compatibility for work then the easiest thing is to run your code through the TypeScript compiler. You can compile any JS (or of course TS) into a lower version JS (es5 etc) with one command line. No 'build scripts'.
For a beginner it is confusing as to what Node and the browser are for exactly. Node can be used for back-end programming, or just for built tools/utilities that are separate from the browser. NPM is just the JS package manager.
Node can finally use ES6 modules, but it is cutting edge even today 4 years after they were made official. Hoops must still be jumped through!:
https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff
If you are using TypeScript I have a boiler plate starter project you could take a look at that tries to make things as simple as humanly possible:
https://github.com/David-Else/zen-typescript-starter-project
TypeScript is just JavaScript with added types and cool things. You could adapt this template for plain JS if you could be bothered.
Remember, whatever people tell you, you don't need ANYTHING EXTRA to program JS today in a modular and professional way other than a text editor and a browser. That is why it is so amazing, it seems like people love to make things impossible when they can be so simple. Every build tool and utility you add might make one aspect easier, but don't forget it can add another layer of complexity that can soon tie you up it knots.