by Clyd3Radcliff3 on 8/5/24, 6:52 AM with 67 comments
Do you have any tip for learning js at it's fundamentals? internals, advanced patterns and everything that can relate to understand it in deep?
by rauschma on 8/5/24, 12:36 PM
Tips:
• If you like static typing, you’ll want to use TypeScript. It’s more work to set up, but it catches many bugs, especially subtle ones where JavaScript’s semantics are not intuitive.
• I learned a lot about JavaScript (and Node.js) by writing shell scripts in Node.js.
My books on JavaScript, TypeScript and Node.js shell scripting are free to read online and target people who already know how to program: https://exploringjs.com
by AshleysBrain on 8/9/24, 9:26 AM
I'm now a huge fan of JavaScript - I think it's a really underrated language. People often still talk about it like it's 2010. The modern language features are amazing, the performance is incredible - including the GC performance - and it's memory safe and no need to worry about allocations. If you want static typing, use TypeScript, which is also very good and is basically a static type layer over JavaScript.
My advice is look at the modern language features which now have wide cross-browser support, and be sure to use them. It can significantly change your coding style for the better. By that I mean things like modules, private class fields, nullish coalescing, optional chaining, async/await, map/set - some of which are fairly old now but are still getting new improvements worth knowing about.
by rikroots on 8/5/24, 7:21 AM
More seriously, the MDN documentation is really useful[1]. Some of the advanced topics listed on that page may be a good place for an experienced engineer to start?
- Inheritance and the prototype chain - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inhe...
- Memory management - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memo...
- The event loop - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Even...
[1] - https://developer.mozilla.org/en-US/docs/Web/JavaScript
by aswerty on 8/9/24, 9:42 AM
There is nothing wrong with JavaScript as a language beyond it's, originally questionable, foundations that have since been iterated upon (much like PHP).
As a massive fan of static typed languages. There is no denying that dynamic typed languages are more fun to develop with in smaller project. It just they often hit a tipping point when they become a horror to deal with. I can still remember my first legacy Python code based where everything was thrice nested dictionaries.
by flohofwoe on 8/9/24, 9:29 AM
With those two things (a static type system layer, and strict linting) JS is actually a quite decent language nowawadays, especially in VSCode (e.g. see: https://code.visualstudio.com/docs/languages/typescript).
by aristofun on 8/7/24, 2:35 AM
There not much advanced to learn.
Thanks to single threaded design you basically just write whatever you intend to do and it works.
With a proper mix of oop and fp there is no place for “advanced patterns” and other over-engineering diseases in a lean js world.
The most terrible and ungly js code ive seen are from former .net and java developers.
I suggest you unlearn all the “patterns” and keep it as simple ad possible.
by rom1v on 8/9/24, 9:44 AM
I would recommend:
by bubblebeard on 8/9/24, 9:33 AM
The biggest reason for this being that the execution of JS code it down to the browser rendering the page where it’s deployed. As such it’s practically impossible to get any code to run consistently. This is of course only relevant in my day to day work as a web dev.
That aside, JS has some funny behavior. If you wish toninderstand JS better you could read up on how null and undefined works.
You could also read up on how functions work, they are objects actually.
by emil0r on 8/9/24, 9:24 AM
This is Clojure based, but there is a lot of similarity to js once you get past the syntax: https://mishadoff.com/blog/clojure-design-patterns/
by mo_42 on 8/9/24, 9:26 AM
I've read the book and watched a similar series on YouTube.
by ryandvm on 8/9/24, 1:25 PM
I remember clearly the days of callback hell. You didn't change your mind about JavaScript, JavaScript changed it's mind about being a real language.
I will give it credit, I don't know of another programming language that has changed so drastically and so much for the better.
by jokethrowaway on 8/9/24, 10:17 AM
Scripting languages are faster for prototyping but they are a nightmare for maintenance. TypeScript might look like a good middle ground but the many escape hatches really allow you a single bad coder to wreck havoc in your codebase. You can't trust a codebase you don't know in TypeScript the same way you would trust a Rust codebase.
JS is good for job security because the node.js hype cycle brought a lot of JS in enterprise places - it's been used for massive codebases and now there are plenty of microservices nobody wants to touch or know how to debug. The rise of horrible, enterprisey frameworks (eg. NestJS) helped this. JS could be the COBOL of the next generation, if it weren't for the web, which will likely keep JS alive for a long time.
If you really want to learn JS, focus on the good parts.
Avoid classes and `this`, avoid prototypal inheritance.
Postpone the frontend as much as you can as that changes every 5 minutes.
Start with bun (if you have no dependencies on node, it's not really compatible), so you'll have no issues with imports / require and all the tooling / transpiling (which rightly give JS a bad name)
by MatthiasPortzel on 8/9/24, 10:19 AM
I would recommend getting your head around closures. It’s possible to statically determine what variables exist in which scope, and so if you can nail down those rules it makes analyzing code much easier.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Clos...
I would recommend a light linter. I see too much new JavaScript code using `var` written by non-JS devs in 2024.
But I don’t think you need TypeScript if you’re first learning the language. Instead, revel in the dynamically-typed flexibility, and learn the error messages JS gives. There are only really 4 or 5 things that will cause JS to error, which can make debugging difficult initially, but once you learn those error messages, it makes debugging comparatively easy.
by 8fingerlouie on 8/9/24, 9:51 AM
I still much prefer strongly typed languages for anything that needs to be maintained, and i've always hated JS with a passion.
What finally convinced me that JavaScript might have it's merits was working on an application written in TypeScript. In my opinion (and not everybody elses) TypeScript fixes a lot of "flaws" not only JavaScript but any duck typed language.
I've long used type hints in Python, but they rely on the editor/tooling to find stuff that doesn't match, where TypeScript finds it compile time. Sure, it's all javaScript in the end, but considering that JavaScript can compare Apple and Orages and decide they're all tomatoes, having compile time type checking is a god sent.
by pjmlp on 8/9/24, 10:17 AM
While I lean on the static languages front, I am a big fan of dynamic languages as well, like Smalltalk and anything Lisp.
In regards to JavaScript, it isn't the Scheme/SELF we wanted, it is what we got and already quite powerful.
Some advanced stuff, how prototype inheritance works, how the new class model is actually mostly syntax sugar on top of prototype inheritance and not really Java like even if it looks similar, how decorators work (not yet fully there but will come), JIT and GC across the various runtimes, if care about server code how to write native extensions for the various runtimes.
by JoeCortopassi on 8/7/24, 4:03 PM
Too many times, when people complain about javascript, what they are really complaining about is the hectic nature of web development. You have three trillion dollar companies (Google/Chrome, Microsoft/Edge, Apple/Safari) actively fighting over agreed upon standards for how the dom is rendered and manipulated. Try and learn any language in that environment, and you'll have a very frustrating time
Why functional programming? Javascript was one of the earlier mainstream languages to support passing around functions as first class citizens, and it's often an aspect of the language that gets downplayed. By and large, javascript sits at the sweet spot of allowing you to do cool functional programming concepts, without all the strictness and verbosity of a language like Haskell. Is that a good thing? It depends, obviously. But for the sake of "Change my mind", this is where I bet you'll start looking at it in a different light
I'm not saying it's the best/one-true language. It's just another cool tool to have on your tool belt
by dabber on 8/9/24, 5:39 PM
https://github.com/getify/You-Dont-Know-JS
When I was beginning to develop a deeper understanding of JS a few years ago, that book, Kyle's talks, and conference presentations by Chrome's V8 team were very helpful for me. It looks like Kyle has expanded the content considerably since then too.
by spion on 8/9/24, 10:15 AM
For the base language I recommend Dr. Axel Rauschmayer's books (https://exploringjs.com/) as they're kept very much up to date.
Where things get really interesting is TypeScript, which takes all of this dynamism and manages to model it with a type system that doesn't feel all that constraining. It also ameliorates most of the core language papercuts. I don't really have good recommendations for TypeScript for now, other than browsing typescript issues and pull requests for examples written by Anders Hejlsberg
You have to be very careful with the library and tooling ecosystem, however. There are a billion ways to do things, many of them incompatible with each other, and things break all the time. This includes major, popular libraries and frameworks with good looking documentation websites, so it can be difficult to pick something solid and stable. This is where most of the pain of using JS comes from.
by JonChesterfield on 8/9/24, 10:01 AM
Most stuff written in javascript makes me nauseous. The entire NPM ecosystem is a parody of software development. But you can ignore essentially all of the libraries and still get work done.
by chkry on 8/7/24, 1:10 PM
by ativzzz on 8/7/24, 2:44 PM
Build something you think is fun. Take a static index.html page without any build tooling (just open the file with a browser), link a JS & CSS file to it, and make a cool thing with animations or interactivity. Maybe try to remake some cool interactive thing you saw somewhere
by vhcr on 8/9/24, 3:45 PM
https://github.com/tc39/proposals/blob/main/finished-proposa...
by can16358p on 8/9/24, 9:59 AM
TypeScript adoption over plain JS is HUGE in the recent years, I wouldn't be surprised if it becomes the native default in browsers some time in the future.
by jacobp100 on 8/9/24, 10:12 AM
by izolate on 8/9/24, 2:05 PM
by 727564797069706 on 8/9/24, 9:47 AM
Once I feel the need for TypeScript, I've done something wrong. For example, built my whole frontend with JavaScript or built my backend in JavaScript.
JavaScript's use case for me is sprinkling it where needed in browser. Anything extra and it feels wrong tool for the job.
Frankly, I believe whole existence of TypeScript is a mistake – we should've never used JavaScript at a scale where static typing becomes necessary.
Having said all that, I'd love to be able to write gradually typed JavaScript (i.e. TypeScript) in the browser. Gradual typing is still greatly beneficial, even in my sprinkles.
by ivanjermakov on 8/9/24, 9:49 AM
JS is no longer as slow as people say, especially when developers are cautious about memory allocations and time complexity.
by contrarian1234 on 8/9/24, 10:18 AM
https://www.destroyallsoftware.com/talks/wat
C has lots of uglyness and quirks but it has the excuse of being ancient - when people knew less. Zig/Hare are attempts to revisit the space with cleaner designs
Somehow several decades later something even more gross was created. No thanks. And the "well just stick to the good parts" stinks of C++
Thankfully there's Clojurescript if I ever need to touch the browser
by chpatrick on 8/9/24, 10:15 AM
by d13 on 8/9/24, 9:36 PM
by Gettingolderev on 8/9/24, 9:57 AM
If you just want to hack around it, hey just use it as any other scripting language
by IshKebab on 8/9/24, 9:15 AM
Projects don't have to become very large at all before static types are better & more productive than dynamic types. Especially for multi-person projects, or ones that last for a while so you forget stuff.