TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Changing my mind about JavaScript

54 点作者 Clyd3Radcliff39 个月前
I&#x27;m a longtime developer software developer with statically typed languages, in the last few weeks i started working on a couple javascript projects and i must say that i&#x27;m changing my mind about javascript, albeit i still think that for bigger project relying on statically typed languages is a better and safer path, i think that JS deserve a chance to be &quot;really&quot; learned, i&#x27;m not referring following the dozens of tutorial we find online that are pure crap (using dozens on stuping npm packages or using pre-cocked solutions without really understanding it&#x27;s full potential).<p>Do you have any tip for learning js at it&#x27;s fundamentals? internals, advanced patterns and everything that can relate to understand it in deep?

32 条评论

rauschma9 个月前
I have used many languages in my nearly 40 years as a programmer (Scheme, C++, Java, Python, Haskell, OCaml, Rust, etc.) and still enjoy JavaScript: It’s decent as a language and there is so much you can do with it.<p>Tips:<p>• 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.<p>• I learned a lot about JavaScript (and Node.js) by writing shell scripts in Node.js.<p>My books on JavaScript, TypeScript and Node.js shell scripting are free to read online and target people who already know how to program: <a href="https:&#x2F;&#x2F;exploringjs.com" rel="nofollow">https:&#x2F;&#x2F;exploringjs.com</a>
评论 #41200387 未加载
评论 #41263131 未加载
评论 #41200199 未加载
AshleysBrain9 个月前
I did a lot of coding with C++ and ended up moving to 100% JavaScript for our game creation tool Construct (www.construct.net).<p>I&#x27;m now a huge fan of JavaScript - I think it&#x27;s a really underrated language. People often still talk about it like it&#x27;s 2010. The modern language features are amazing, the performance is incredible - including the GC performance - and it&#x27;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.<p>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&#x2F;await, map&#x2F;set - some of which are fairly old now but are still getting new improvements worth knowing about.
rikroots9 个月前
If you have plenty of time, start a side project to build out a HTML canvas library (with no dependencies) ... just kidding! I&#x27;ve been building my canvas library for 11 years and there&#x27;s still a shedload of JS understanding I&#x27;ve not yet poked.<p>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?<p>- Inheritance and the prototype chain - <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Inheritance_and_the_prototype_chain" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Inhe...</a><p>- Memory management - <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Memory_management" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Memo...</a><p>- The event loop - <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Event_loop" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Even...</a><p>[1] - <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript</a>
aswerty9 个月前
Static types are sanity when the people and years keep increasing. It isn&#x27;t at all important in small one man projects since most of your defined types are in your head in any case.<p>There is nothing wrong with JavaScript as a language beyond it&#x27;s, originally questionable, foundations that have since been iterated upon (much like PHP).<p>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.
评论 #41200356 未加载
评论 #41200355 未加载
评论 #41200427 未加载
flohofwoe9 个月前
I would recommend using Typescript and a strict linter if possible. TS is essentially modern Javascript plus static typing (so by learning TS, you also learn JS as a side effect), and strict linting rules will reject outdated Javascript features and nudge you towards the &#x27;good parts&#x27;.<p>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: <a href="https:&#x2F;&#x2F;code.visualstudio.com&#x2F;docs&#x2F;languages&#x2F;typescript" rel="nofollow">https:&#x2F;&#x2F;code.visualstudio.com&#x2F;docs&#x2F;languages&#x2F;typescript</a>).
评论 #41200298 未加载
评论 #41201572 未加载
aristofun9 个月前
JavaScript is flexible and simple in a good sense of the word.<p>There not much advanced to learn.<p>Thanks to single threaded design you basically just write whatever you intend to do and it works.<p>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.<p>The most terrible and ungly js code ive seen are from former .net and java developers.<p>I suggest you unlearn all the “patterns” and keep it as simple ad possible.
rom1v9 个月前
&gt; Do you have any tip for learning js at it&#x27;s fundamentals?<p>I would recommend:<p>- <a href="https:&#x2F;&#x2F;eloquentjavascript.net&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eloquentjavascript.net&#x2F;</a><p>- <a href="https:&#x2F;&#x2F;javascript.info&#x2F;" rel="nofollow">https:&#x2F;&#x2F;javascript.info&#x2F;</a>
评论 #41201443 未加载
评论 #41200285 未加载
bubblebeard9 个月前
I have been using JS for more than 20 years, and I do not like it. There are parts of it I find useful, but I avoid using it as much as I can in any project.<p>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.<p>That aside, JS has some funny behavior. If you wish toninderstand JS better you could read up on how null and undefined works.<p>You could also read up on how functions work, they are objects actually.
评论 #41200259 未加载
emil0r9 个月前
There is a functional core in js, and as such it might be an idea to take a look at common OOP design patterns and how they translate to an FP approach.<p>This is Clojure based, but there is a lot of similarity to js once you get past the syntax: <a href="https:&#x2F;&#x2F;mishadoff.com&#x2F;blog&#x2F;clojure-design-patterns&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mishadoff.com&#x2F;blog&#x2F;clojure-design-patterns&#x2F;</a>
mo_429 个月前
There&#x27;s JavaScript The Good Parts by Douglas Crockford.<p>I&#x27;ve read the book and watched a similar series on YouTube.
评论 #41200274 未加载
评论 #41200421 未加载
评论 #41205618 未加载
ryandvm9 个月前
Been coding for 30+ years. In the last 5 years I have come around to not hating JavaScript (TypeScript really), but let&#x27;s be honest, it took 15 years of hearing the JS community tell us &quot;sure JavaScript used to be awful, but now it&#x27;s finally good&quot; for it to actually be true.<p>I remember clearly the days of callback hell. You didn&#x27;t change your mind about JavaScript, JavaScript changed it&#x27;s mind about being a real language.<p>I will give it credit, I don&#x27;t know of another programming language that has changed so drastically and so much for the better.
评论 #41203581 未加载
jokethrowaway9 个月前
I&#x27;ve been doing JS for 18 years. I don&#x27;t think it particularly deserves to be learned but I think in general you should know a scripting language and JS is very popular (and can be embedded with v8 isolates fairly easily). If you know python or lua I wouldn&#x27;t bother. Lua would probably be my first choice.<p>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&#x27;t trust a codebase you don&#x27;t know in TypeScript the same way you would trust a Rust codebase.<p>JS is good for job security because the node.js hype cycle brought a lot of JS in enterprise places - it&#x27;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&#x27;t for the web, which will likely keep JS alive for a long time.<p>If you really want to learn JS, focus on the good parts.<p>Avoid classes and `this`, avoid prototypal inheritance.<p>Postpone the frontend as much as you can as that changes every 5 minutes.<p>Start with bun (if you have no dependencies on node, it&#x27;s not really compatible), so you&#x27;ll have no issues with imports &#x2F; require and all the tooling &#x2F; transpiling (which rightly give JS a bad name)
MatthiasPortzel9 个月前
JavaScript is one of my favorite languages. It has the nearly unique design constraints of having multiple implementations and being unwilling to break backwards compatibility, which gives it a lot of warts that are easy to ridicule. But I think the language on the whole is very flexible, very simple, and very usable.<p>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.<p><a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Closures" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Clos...</a><p>I would recommend a light linter. I see too much new JavaScript code using `var` written by non-JS devs in 2024.<p>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.
8fingerlouie9 个月前
I have a long history developing stuff in strongly typed languages, C, C++, C#, Go, Rust, Java and Kotlin but have always done the &quot;quick and dirty&quot; in Perl, Ruby or more recently Python or Kotlin.<p>I still much prefer strongly typed languages for anything that needs to be maintained, and i&#x27;ve always hated JS with a passion.<p>What finally convinced me that JavaScript might have it&#x27;s merits was working on an application written in TypeScript. In my opinion (and not everybody elses) TypeScript fixes a lot of &quot;flaws&quot; not only JavaScript but any duck typed language.<p>I&#x27;ve long used type hints in Python, but they rely on the editor&#x2F;tooling to find stuff that doesn&#x27;t match, where TypeScript finds it compile time. Sure, it&#x27;s all javaScript in the end, but considering that JavaScript can compare Apple and Orages and decide they&#x27;re all tomatoes, having compile time type checking is a god sent.
pjmlp9 个月前
I have started with a dynamic language with optional typing (BASIC), back in 1986, went through several static and dynamic typing throughout the years.<p>While I lean on the static languages front, I am a big fan of dynamic languages as well, like Smalltalk and anything Lisp.<p>In regards to JavaScript, it isn&#x27;t the Scheme&#x2F;SELF we wanted, it is what we got and already quite powerful.<p>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.
JoeCortopassi9 个月前
I think the best way to understand&#x2F;appreciate javascript as a language is to A) separate it from the DOM, and B) take a functional programming focus<p>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&#x2F;Chrome, Microsoft&#x2F;Edge, Apple&#x2F;Safari) actively fighting over agreed upon standards for how the dom is rendered and manipulated. Try and learn <i>any</i> language in that environment, and you&#x27;ll have a very frustrating time<p>Why functional programming? Javascript was one of the earlier mainstream languages to support passing around functions as first class citizens, and it&#x27;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 &quot;Change my mind&quot;, this is where I bet you&#x27;ll start looking at it in a different light<p>I&#x27;m not saying it&#x27;s the best&#x2F;one-true language. It&#x27;s just another cool tool to have on your tool belt
dabber9 个月前
I&#x27;m surprised that Kyle Simpson&#x27;s, _You Don&#x27;t Know JS_ hasn&#x27;t been mentioned in this thread.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;getify&#x2F;You-Dont-Know-JS">https:&#x2F;&#x2F;github.com&#x2F;getify&#x2F;You-Dont-Know-JS</a><p>When I was beginning to develop a deeper understanding of JS a few years ago, that book, Kyle&#x27;s talks, and conference presentations by Chrome&#x27;s V8 team were very helpful for me. It looks like Kyle has expanded the content considerably since then too.
spion9 个月前
There is honestly not much to learn, and that might be part of the appeal. At its core, JS is a relatively simple dynamic language with a clean syntax. Despite the clean syntax there are quite a few quirks in how some of the internals work (sorting and pervasive string comparison and casting, equality operator, etc). The most interesting thing about it is probably the programming model of free-form objects and closures: rather than using classes, you could write functions that return free-form records containing functions (and getters) that close over the lexical scope of the function. This gives a kind of dynamic object construction flexibility without the additional boilerplate.<p>For the base language I recommend Dr. Axel Rauschmayer&#x27;s books (<a href="https:&#x2F;&#x2F;exploringjs.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;exploringjs.com&#x2F;</a>) as they&#x27;re kept very much up to date.<p>Where things get really interesting is TypeScript, which takes all of this dynamism and manages to model it with a type system that doesn&#x27;t feel all that constraining. It also ameliorates most of the core language papercuts. I don&#x27;t really have good recommendations for TypeScript for now, other than browsing typescript issues and pull requests for examples written by Anders Hejlsberg<p>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.
JonChesterfield9 个月前
I love writing javascript. It behaves like a lisp which really likes hashtables and runs on some of the best compiler tech anyone has shipped. Typescript is an interesting layer I haven&#x27;t used enough.<p>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.
chkry9 个月前
I love JavaScript, been programming for more than 16 years now. Built websites, apps, banking portals, chat bots and customer experience software using Js, React, Redux and TypeScript. Also used Java and currently work on Go lang. Even after using every language I still prefer JS to be my everyday work love language. Its better now and improving too.
ativzzz9 个月前
&gt; Do you have any tip for learning js at it&#x27;s fundamentals?<p>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 &amp; CSS file to it, and make a cool thing with animations or interactivity. Maybe try to remake some cool interactive thing you saw somewhere
vhcr9 个月前
Once you understand the fundamentals, knowing about the newer stuff would be a good step forwards:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;proposals&#x2F;blob&#x2F;main&#x2F;finished-proposals.md">https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;proposals&#x2F;blob&#x2F;main&#x2F;finished-proposa...</a>
can16358p9 个月前
I strongly suggest TypeScript, which is (as you probably already know) JavaScript with static typing: in other words exactly what you want.<p>TypeScript adoption over plain JS is HUGE in the recent years, I wouldn&#x27;t be surprised if it becomes the native default in browsers some time in the future.
jacobp1009 个月前
The industry uses TypeScript these days. If you’re inheriting a project, write the new stuff in TS, and gradually migrate. If you’re using the modern syntax, I’d say JS behaves mostly like every other language, with the exception being the tooling landscape is massive
izolate9 个月前
I started my career with JavaScript and Node.js, but over time I&#x27;ve grown to dislike its design flaws and dynamic nature. If JavaScript had Dart&#x27;s strengths, I might still be using it; instead, I&#x27;ve moved on to languages I find more respectable.
7275647970697069 个月前
My (unpopular?) take is that JavaScript should suffice.<p>Once I feel the need for TypeScript, I&#x27;ve done something wrong. For example, built my whole frontend with JavaScript or built my backend in JavaScript.<p>JavaScript&#x27;s use case for me is sprinkling it where needed in browser. Anything extra and it feels wrong tool for the job.<p>Frankly, I believe whole existence of TypeScript is a mistake – we should&#x27;ve never used JavaScript at a scale where static typing becomes necessary.<p>Having said all that, I&#x27;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.
评论 #41200332 未加载
ivanjermakov9 个月前
The power of JS is the amount of effort put into its optimization, because of its importance for the web.<p>JS is no longer as slow as people say, especially when developers are cautious about memory allocations and time complexity.
contrarian12349 个月前
I don&#x27;t write JS, but the Wat talk makes me want to stay as far away as possible<p><a href="https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;wat" rel="nofollow">https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;wat</a><p>C has lots of uglyness and quirks but it has the excuse of being ancient - when people knew less. Zig&#x2F;Hare are attempts to revisit the space with cleaner designs<p>Somehow several decades later something even more gross was created. No thanks. And the &quot;well just stick to the good parts&quot; stinks of C++<p>Thankfully there&#x27;s Clojurescript if I ever need to touch the browser
chpatrick9 个月前
I think TypeScript is a legitimately fantastic language and I&#x27;ve used everything from C++ to Haskell.
d139 个月前
Cristian Salcescu‘s books on JavaScript are absolutely marvellous and must-reads.
Gettingolderev9 个月前
JS is broken and TypeScript is a way of fixing it but at the end of the day, you use Frameworks anyway like Anguular.<p>If you just want to hack around it, hey just use it as any other scripting language
评论 #41200458 未加载
IshKebab9 个月前
I mean why not use Typescript and have both?<p>Projects don&#x27;t have to become very large at all before static types are better &amp; more productive than dynamic types. Especially for multi-person projects, or ones that last for a while so you forget stuff.
评论 #41200261 未加载