7 Useful Javascript Tips
Without further ado, lets dive into it:
Filtering falsy values:
If you have an array of values, you can f...
For further actions, you may consider blocking this person and/or reporting abuse
On the last one perhaps there is a formatting error, since comment is affecting the const declaration:
Thanks, I'll give it an edit!
Thanks for sharing. It's good to know tricks even if it's not good to use them.
Example with implicit number coercion on Date is misleading. I'll be disappointed to see it in some produciton code.
Ahh true, that looks much more understandable. Thanks for the feedback!
From my experience, 2, 3 & 5 aren't significantly faster and make the code harder to read/understand. I avoid these by enabling eslint rules to disable implicit coercion.
Tip 7 can soon be replaced by the new ES2020 Promise.allSettled() feature.
True, readability is a good point. Thanks for the feedback!
Shorter way to filter falsey values:
Maybe you should mention that double tilde operator (~~) for negative numbers acts like Math.ceil() function, in your example:
const x = -1.5
const y = ~~x
console.log(y) // Equals -1
Nice article btw :)
Awesome, didn't know about that. Thanks for sharing!
Nice - I learned one there. I've mostly used
|0
to floor numbers but I like the~~
prefix style a lot too. I like the parameter validation one too. That's nice.Oh awesome, didn't know about that one, thank you!
Nice!
Nice!
Awesome read
Informative in short way Thanks
Awesome and helpful tips! Definitely learned something from this