惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
罗磊的独立博客
J
Java Code Geeks
人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
The GitHub Blog
The GitHub Blog
G
Google Developers Blog
U
Unit 42
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
Jina AI
Jina AI
F
Fortinet All Blogs
H
Help Net Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
C
Check Point Blog
GbyAI
GbyAI

Secret Weblog

Becoming More Xee: A Modern XPath and XSLT Engine in Rust Looking for new challenges! Repeat Yourself, A Bit The Curious Case of Quentell The Humble For Loop in Rust The Humble For Loop in JavaScript Don Question Best Practices I Was a 1980s Teenage Programmer Part 5: Achieving Assembly I Was a 1980s Teenage Programmer Part 4: The Call of Assembly The Tooling Shift I Was a 1980s Teenage Programmer Part 3: MSX-2 Empowering Programming Languages Bloat and Retrofuturism Refreshing my Blog Again Random Rust Impressions Apilar: An Alife System I Was a 1980s Teenage Programmer Part 2: Olivetti M24 I Was a 1980s Teenage Programmer: the Alphatronic SolidJS fits my brain Is premature optimization the root of all evil? Framework Patterns: JavaScript edition Roll Your Own Frameworks Framework Patterns Secret Weblog Highlights Refactoring to Multiple Exit Points mstform: a form library for mobx-state-tree Seven Years: A Very Personal History of the Web Morepath 0.16 released!
JavaScript: when you need two ways to do it!
Martijn Faassen · 2024-05-28 · via Secret Weblog

JavaScript is a cool language. (Yes, you are cool too, TypeScript.) I've used JavaScript a lot. (Yes, TypeScript, I've used you a lot as well.)

JavaScript has a strange design on the expression level, but by ignoring those bits, the language is usable enough. (Yes, TypeScript, you have the same strange design but you give more compile-time errors to stop devs from blundering into some of it.)

What's especially cool is that JavaScript has two of everything. (Yes, TypeScript, you have two of everything too!)

  • undefined and null.
  • == and ===.
  • function and arrow functions (=>).
  • const and let. Fun fact: const variables aren't immutable, you just can't rebind them.
  • var versus those new ones, const and let. Okay, maybe that's three ways to declare a variable, but we're not going to let it ruin a good post.
  • for loops and forEach.
  • for of and for in. Just don't use for in anymore.
  • require() and import.
  • named and default exports. export vs `export default
  • named and default imports too! import {thing} vs import thing.
  • await and then() for async! (and callbacks, but again we're not letting that ruin a good post)
  • classes and prototypes.
  • arguments and ... for when you want to pass variable arguments to a function.
  • test() and it() to declare tests in Jest.
  • npm and yarn (and all the other ones, okay...)
  • object and Map. For when you need a hash table.
  • Boolean and "boolean". They're different! If you get the type of a boolean you get '"boolean"', not '"Boolean"'.
  • true and false. Wait.
  • String and "string", Object and "object", String and "string". (Yes, TypeScript, you make the lowercase ones into proper static types. But you can use the uppercase ones as static types too. But you shouldn't.)
  • XMLHTTPRequest and fetch for when you want to talk to a server.
  • (Yes, TypeScript, you have type and interface and JavaScript doesn't. Well done!)
  • JavaScript even has two names! JavaScript and ECMAScript.
  • Unlike most programming languages, the name consists of two words. Java, and Script. (Yes, TypeScript, you have two words in your name too.)

JavaScript, if you need two ways to do it!

Yes, TypeScript, you too.

Copied! Copy code to clipboard