Doing String(foo) instead of '' + foo is casting to the String Object as opposed to working with a simple string literal, which is going to incur a performance hit.
Good to know. I prefer cleaner code over more peformance by default, and optimize when that is required. It's the same reason I use forEach instead of for by default.
By the way, the Jsperf link you posted doesn't directly apply to what we're talking about. Here's a better comparison.
10
u/nawitus Mar 27 '15
Mostly good stuff.
I prefer String(foo) instead of '' + foo.
I think 4 spaces are better than 2.
'collection.length > 0' is perfectly reasonable, there's no need to use shortcuts whenever possible.
I've always used "that" over "_this", but these days this is rarely needed thanks to the fat arrow syntax.