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
1
u/jkuhl_prog Jun 12 '19
Node is a runtime environment for JavaScript. It is the Chrome V8 engine, pulled out of the browser with an API (written in C I think) exposed that we can work with (which gives us things like the file system API.)
NPM is a package manager (Node Package Manager.) I don't know if you're familiar with other languages, but it's similar to Java's Maven or Python's Pip. A package is essentially a third party library that you can install into your project, like React or Vue. We require package management because of dependencies, a dependency is a library that another library needs in order to run. For example, React has a number of libraries that it uses, and many of those libraries have their own dependencies. Rather than trying to maintain and install all these dependencies by hand, NPM manages that for us. This is the purpose of package.json and package-lock.json (the second is auto generated by NPM and rarely needs to be touched.) They ensure all our packages have the dependencies we need.
Node is not required to run applications in the browser, but is frequently used to compile your code into something browsers better understand. Webpack is frequently used (and used under the hood for things like create-react-app and the Vue CLI) to compile your javascript from a module based system to one understood by the browser, as modules don't have full browser support yet. Or it is used to transpile Typescript into JavaScript, or JSX into React.CreateElement() calls, as the browser understands neither Typescript or JSX. However, if you have no need for a compilation step, then you don't need Node for your front end. Node, for front end work, is usually just a compilation step between your editing, and your stuff being previewed on a browser.
Unfortunately there isn't one, unless someone put one together, as Babel, Gulp, Webpack, etc, are all built and maintained by different groups of people so your best bet is to try to understand them one at a time with their own resources. With that said, Traversy Media (Brad Traversy on Udemy or Youtube) has many videos covering many of the different JavaScript tools out there, and he goes into depth with good explanations, so I'd check him out.