I think the caching length was the most useful advice. But I would say try to avoid looping arrays overall. I would say try and accomplish your loops with some recursion once in a while. But this is only for very large arrays really.
Lots of good advice here, but the article is showing its age a bit; some of these can now be achieved with ES6 more succinctly:
4) Default values using || operator
function User(name = 'Oliver Queen', age = 27) {
// ...
}
(though || is still very useful!)
10) Merge arrays:
[...arr1, ...arr2]
11) Convert nodelist:
[...document.querySelectorAll("p")]
(Unsure about any supposed "memory usage" advantages stated)
I'd also say that 2 and 3 can, depending on the circumstances, be seen as being "too clever" by some linters. YMMV!
Watch out! 4) A user with a completely valid age of 0, gets a age set to 27!!
Nice collection & useful..
Most of them are not hacks, but just using JS correctly. All in all, though, this might be a useful list for JS beginners, thanks for sharing!
Victor Oliveira
1) Even if you insert a value lower than zero, it will return true, for example if you have an account with negative balance. You could add a aditional condition:
this.hasMoney = !!cash && cash > 0;