DEV Community

Discussion on: JavaScript is almost pythonic

Collapse
 
math2001 profile image
Mathieu PATUREL

Hmm... Good comparaison, JS is definitely getting better, but still.

Quick thougts:

Everything is an Object in JS (including arrays), there isn't any proper equivalent of python's magic functions (add for example).

One thing that horrifies me: how to convert a integer to string: '' + 2.

I think JS' ecosystem is awesome, but JS in itself absolutely sucks. Pretty much the opposite of Python.

Collapse
 
elarcis profile image
Elarcis • Edited

No need to be that categorical in your judgement, your '' + 2 code sample has always been outdated, as String(2) or (2).toString() have been allowed since the 1997 standard (source).

It’s possible to do awful code in a lot of languages, Python included, finding the worst in a tech is not a proof of it “sucking” ;)

Collapse
 
schnubb profile image
Schnubb

There's a method for that:

const x = 2;
x.toString(); // "2"
Collapse
 
elarcis profile image
Elarcis • Edited

Or as an alternative, String(x), which does exactly the same thing, except if x is null or undefined, then it produces 'null' or 'undefined' instead of throwing an error.