I find it bizarre how people evaluate how good programming languages are based only on abscence of weakness while seemingly ignoring strengths.

This is what make many look down upon JavaScript.
JavaScript’s good parts are actually better than the good parts of other high-level languages. JavaScript allows you to effortlessly create closures and objects in ways that are super tedious in other languages.
Only one that I know that is comparable is Lua, which is like a super clean take on JavaScript.
I think it’s valuable to be able to programming with as few concepts as possible and JavaScript shines in this regard.

Variables, control structures, functions as values and combined with scoping that allows for closures is all you really need in JavaScript do do so much.
Want to create objects? No need for class (though we kinda have it) or even prototypes (which we do have).

Just create a function that returns an object literal with functions on it. The variables it closes over are the private variables.

const createVector
const createSomeObj = () => {
let towels = 42;

return {
amountOfTowels: () => {
return towels;
},
useTowel: () => {
towels -= 1;
},
};
}
Using very basic building blocks of JavaScript that you already use in regular functions (scope, variables, etc…) you can create objects.

And everything is just there to see. Easy to understand.
Classes and objects in languages like Python, Ruby, Java are basically kinda mysterious to many beginners (to be fair: prototypes too, but you can create objects without them in JS).

Private member variables appear different from normal variables used in functions.
Private members (or the equivalent to it) are just… regular variables in JavaScript. That’s it. The same rule as all the others apply.
Granted: understanding closures and scoping in JavaScript can be kida hard. It’s one of those ideas that are very simply, but slightly subtle.

But it’s not _that_ hard either, and I frankly think it’s easier to understand than classes.
JS got some of these ideas from Scheme. I ecommend reading even just a few chapters of Structure and Interpretation of Computer Programs.

It really teaches you to closures in a fantastic way (among many other cool ideas).

https://mitpress.mit.edu/sites/default/files/sicp/index.html
It’s available online for free:
I don’t think anything has improved me as a JavaScript programmer as much as reading just a little from SICP.

It really made me appreciate JavaScript so much more.
Oh to go back to the beginning theme of this thread: I’ve probably been guilty of judging languages only on their weakness themselves.

PHP is a good example. I only know what’s bad about it. I don’t really the good parts of PHP. Maybe it has great parts?
You can follow @torb_xyz.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: