DEV Community

Discussion on: 10 Practical JavaScript Tricks

Collapse
 
bdougherty profile image
Brad Dougherty

Agreed with some other comments that there are quite a few issues here.

1- Better to use the standardized Array.from() which is designed for use with array-like objects such as arguments. Better yet, rest parameters should be used when possible, since they are more explicit than arguments.

3- Perfectly valid syntax, but using the if is much more clear and explicit about the intention.

4- Using default parameters is not only more explicit, but it also avoids issues when you want a falsy value to be possible (the code in the article will not allow 0 for example, but that might be completely valid)

function doSomething(arg1 = 32) {
    // … do something here
}

5- Not sure there is actually a practical application of this. I sound like a broken record at this point, but since most people do not know this, it makes the code much more difficult to read. Always be explicit.

6- array.slice() is more clear about the intentions.

10- This is a great one. I use it

Being responsible is far more important than being efficient.

That closing thought is extremely important, unfortunately most of the tricks here are ultimately not responsible.