r/programming • • May 09 '12

JavaScript: The good parts

http://blog.movereem.nl/images/javascript-the-good-parts-the-definitive-guide.jpg
645 Upvotes

159 comments sorted by

View all comments

0

u/jaylink May 09 '12

Yes, it's a funny pic, but in reality it has more to do with Crockford's book not being that good rather than the language itself sucking. Aside from the terrible choice of using "+" as a concatenation operator, Brendan Eich did a fantastic job with Javascript. And he had, what? Two weeks?

Typically problems with JS are due to the DOM being slow and not due to JS itself. That, or people who don't know what they're doing.

3

u/yeskia May 09 '12

May I ask what is wrong with "+" being the concatenation operator?

1

u/jaylink May 09 '12

Because it is also a mathematical operator, and so should "3" + "3" become "33" or 6? The problem shows up when using variables, as they are "loosely typed" in JS (i.e., the interpreter decides on the fly if it's numeric or alpha).

Other scripting languages solve this by using a period ( . ) for concatenation which makes it explicit. (Hmm, that looks like a boob -- not intentional).

Bonus tip: if you want to ensure that your variable is treated as a numeric value, you can just put a "+" in front of it, like so:

var x = 3; var y = 3; var z = +x + +y;

(You can also use parseInt() but the plus is simpler.)

1

u/doomslice May 09 '12

Number(y) also would work, and is more explicit and less error-prone than parseInt (having to remember to supply a radix).