Re:Using const/let instead of var can make JavaScript code r...
by nostrademons on Wednesday October 21, 2020 @02:12AM
(#24845191)
In 2009 we standardized on this form for all Google Search JS for-each loops, because we were literally counting bytes on the SRP:
for(var i=0,e;e=a[i++];){ ... }
Could result in problems if the array contained falsey values, but we just didn't do that.Nowadays, like I mentioned above, I'd just do
arr.foreach((elem, i) => { ... });
Which last time I checked was significantly slower than the for-loop, but I've learned my lesson about trying to optimize for browser quirks that may disappear in a year or two. :-)
Re:Using const/let instead of var can make JavaScript code r...
by layoutIfNeeded on Wednesday October 21, 2020 @04:49AM
(#24845963)
>[...] discovered that access to object properties is faster than accessing array indexes half the time. That was in C language, but it holds true in JavaScript.
What are these object properties in C?
Re:Using const/let instead of var can make JavaScript code r...
by austincheney on Wednesday October 21, 2020 @04:59AM
(#24846004)
Hash map then.
Re:Using const/let instead of var can make JavaScript code r...
by layoutIfNeeded on Wednesday October 21, 2020 @09:54AM
(#24847888)
Hm. So you're saying that indexing into a hash map can be faster than indexing into an array? How would this be possible? I mean, under the hood a hash map is going to an array too, which is being indexed based on the hash value...
Re:Using const/let instead of var can make JavaScript code r...
by austincheney on Wednesday October 21, 2020 @12:01PM
(#24849083)
Hash map properties are randomly accessed from memory opposed to array indexes.
As an added bit of trivia in the 1970s a software developer named Paul Heckel, known for Heckel Diff algorithm, discovered that access to object properties is faster than accessing array indexes half the time. That was in C language, but it holds true in JavaScript.