Live data from Hacker News

A re-introduction to JavaScript

developer.mozilla.org

111–115 of 115 posts

Re: A re-introduction to JavaScript

#111
post #71

Earlier quoted context omitted.

I think nearly every JS engine now optimizes `for (...;i In fact, even `for` is likely an over-optimization. In nearly all JS code you can get away with just using `forEach` (or its friends).

forEach is awfully slow compared to a for statement if you're dealing with numbers - less so with strings/objects, but it's still noticeable (like 10x whenever I've tested it at best). Caching the array length still gives you a small speed boost in most browsers, but it's probably an over optimisation unless you're doing something really intensive.

If you're doing number crunching, yes, don't use forEach.

If you're just writing ordinary business code (i.e. in 80% of all code out there), by all means, please use forEach and friends.

Besides, if you're doing number crunching in JS, you probably want to stick to ASM.js anyway.

Re: A re-introduction to JavaScript

#112
post #18

The article mentions an idiom for iterating over an array. It says 'an even nicer idiom is...' and then it shows it. I just wanted to say that the behaviour of this 'nicer' idiom may not be what's expected - it stops iterating once it hits the first falsy value. I was quite excited actually when I first saw them idiom, until I quickly realized its limitations

I improved the wording:

“A nicer-looking but limited idiom is:”

MDN documentation is on a wiki. You can just edit the page.

Re: A re-introduction to JavaScript

#113

Earlier quoted context omitted.

The reason this is mentioned (and things like the part about caching array length in your for loop) is that this tutorial was mostly written back in 2006, when things were obviously a bit different with JavaScript. The article has gotten updates since then (check the history), but not many and not to the extent it probably needs. Not sure why it keeps getting linked.

Since you seem to have an understanding of what is wrong with it, care to tell about everything you know that should be updated?

I would find that helpful. Since the article is a wiki, I would be willing to edit in any suggestions that magicalist makes, if magicalist doesn’t want to bother doing the editing him or herself.

Re: A re-introduction to JavaScript

#115
post #109

Earlier quoted context omitted.

See if there is a fixed precision arithmetic library for JS? (similar to BigDecimal in Java / Groovy) Homework: 1) Google for such; 2) see which one doesn't suck.

Groovy is a heavily marketed programming language that uses BigDecimal, just like its sister dynamic languages Clojure, Rhino/Nashorn, and Xtend also do. Only Java actually ships BigDecimal.

Yeah, I get that the base JRE is what actually provides the BigDecimal class in this case -- the other languages just use it. (as the default "decimal"-numeric type in the case of Groovy, rather than [Dd]ouble)
Post reply on HN