r/javascript • • Apr 28 '19

7 Useful JavaScript Tricks

https://davidwalsh.name/javascript-tricks
505 Upvotes

36 comments sorted by

View all comments

8

u/DGCA Apr 29 '19

This is a pretty worthless comment, but if you were code golfing...

['', 123, 0, 'foo'].filter(Boolean)
['', 123, 0, 'foo'].filter(x=>!!x)

...the latter is one less character.

1

u/[deleted] Apr 29 '19

[removed] — view removed comment

10

u/SoInsightful Apr 29 '19

The V8 engine is very well-optimized, and will certainly cache the function for you.