5 is probably not very useful and pollutes the namespace (benchmarks? I'd be surprised if this actually sped anything up at all). In most cases, you should be using forEach anyways.
4 is a bad idea if the argument could be falsey.
Don't do #6. Use hasOwnProperty. If you don't actually want to check that, just use document.querySelector (in the example) or document.querySelector != null if the property could possibly be falsey (not true in this case)
Mistake in #10; it doesn't create a new array. The article shows it, but it says it wrong ("which instead creates a new array")
6) #12 is also pretty bad. Not only is it super inefficient, but if you run it a couple thousand times and test to see which element from your original array comes first, you'll find that there isn't an even chance of each value coming up.
1
u/gkx May 08 '16
5 is probably not very useful and pollutes the namespace (benchmarks? I'd be surprised if this actually sped anything up at all). In most cases, you should be using forEach anyways.
4 is a bad idea if the argument could be falsey.
Don't do #6. Use
hasOwnProperty. If you don't actually want to check that, just usedocument.querySelector(in the example) ordocument.querySelector != nullif the property could possibly be falsey (not true in this case)Mistake in #10; it doesn't create a new array. The article shows it, but it says it wrong ("which instead creates a new array")