Re:Ask HN: Changing my mind about JavaScript
by scary-size on Friday August 09, 2024 @05:26AM
(#41200199)
> I learned a lot about JavaScript (and Node.js) by writing shell scripts in Node.js.
Totally! This will give you lot of insights into low-level working of JS. Of course, some Node.js specifics too. Reading from STDIN, parsing strings into structured data etc.
Re:Ask HN: Changing my mind about JavaScript
by pavlov on Friday August 09, 2024 @06:01AM
(#41200348)
For writing shell scripts in Node, there’s a helper library called zx created by Google.
I find it a lifesaver for the common occasion when I’m tempted to write a bash script but also know it’s going to need some slightly more advanced features (as in parsing a JSON, or just arrays that are not totally bonkers in syntax).
Re:Ask HN: Changing my mind about JavaScript
by scary-size on Friday August 09, 2024 @08:01AM
(#41200997)
Yes, I was about to propose this. But then again, the author wants to learn the basics without grappling with abstractions. I think zx can be a bit quirky.
Re:Ask HN: Changing my mind about JavaScript
by pavlov on Friday August 09, 2024 @09:01AM
(#41201429)
For sure there's an element of magic to zx. The use of tagged template literals doesn't look like plain JavaScript even though it's standard.
You need to understand async/wait, promises and tag functions to make sense of this basic zx example:
await $`ls -la`> 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.
It’s worth looking at JSDoc as an alternative to regular TypeScript. No compiler to set up, and you’re restricted in a good way - less likely to get over-engineered types.
Re:Ask HN: Changing my mind about JavaScript
by FireInsight on Friday August 09, 2024 @08:32AM
(#41201205)
I find writing it too hard compared to TS, but in terms of functionality it's pretty good.
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