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.
2
u/PlNG Mar 28 '15
Doing
String(foo) instead of '' + foois casting to the String Object as opposed to working with a simple string literal, which is going to incur a performance hit.Jsperf