JavaScript: when you need two ways to do it!
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!)
undefinedandnull.==and===.functionand arrow functions (=>).constandlet. Fun fact:constvariables aren't immutable, you just can't rebind them.varversus those new ones,constandlet. Okay, maybe that's three ways to declare a variable, but we're not going to let it ruin a good post.forloops andforEach.for ofandfor in. Just don't usefor inanymore.require()andimport.- named and default exports.
exportvs `export default - named and default imports too!
import {thing}vsimport thing. awaitandthen()for async! (and callbacks, but again we're not letting that ruin a good post)- classes and prototypes.
argumentsand...for when you want to pass variable arguments to a function.test()andit()to declare tests in Jest.npmandyarn(and all the other ones, okay...)objectandMap. For when you need a hash table.Booleanand"boolean". They're different! If you get the type of a boolean you get '"boolean"', not '"Boolean"'.trueandfalse. Wait.Stringand"string",Objectand"object",Stringand"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.)XMLHTTPRequestandfetchfor when you want to talk to a server.- (Yes, TypeScript, you have
typeandinterfaceand JavaScript doesn't. Well done!) - JavaScript even has two names!
JavaScriptandECMAScript. - 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.