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!)
undefined
andnull
.==
and===
.function
and arrow functions (=>
).const
andlet
. Fun fact:const
variables aren't immutable, you just can't rebind them.var
versus those new ones,const
andlet
. Okay, maybe that's three ways to declare a variable, but we're not going to let it ruin a good post.for
loops andforEach
.for of
andfor in
. Just don't usefor in
anymore.require()
andimport
.- named and default exports.
export
vs `export default - named and default imports too!
import {thing}
vsimport thing
. await
andthen()
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()
andit()
to declare tests in Jest.npm
andyarn
(and all the other ones, okay...)object
andMap
. 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
andfalse
. 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
andfetch
for when you want to talk to a server.- (Yes, TypeScript, you have
type
andinterface
and JavaScript doesn't. Well done!) - JavaScript even has two names!
JavaScript
andECMAScript
. - 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.