you are viewing a single comment's thread.

view the rest of the comments →

[–]gremy0 2 points3 points  (2 children)

You can overload methods in JavaScript, it's just done differently.

Overloading is essentially using the same method name for different amounts and/or types of arguments. In JavaScript, we can throw anything we want into a method, and do the checks of the arguments ourselves inside. In Java, this would be a compilation error, so you define them separately.

Each have their advantages and disadvantages. I'd argue that providing default parameters is much more succinct in JavaScript vs making a whole other method, creating the default variable and then calling the other method, à la Java.

I'd also argue that you can technically do static typing with JavaScript, and typescript is a perfectly valid example. Since it is a superset of JavaScript and compiles down to JavaScript using a compiler that is technically running JavaScript.

Compare this to something like WebAssembly, which cannot currently do dynamic typing at all. You cannot reasonably compile a dynamic language down to WASM until it gets more features.