r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

43

u/jesusthatsgreat May 28 '19

Formatting dates. You don't need a bulky third party library. toLocaleDateString() will do the job in 99% of cases.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

8

u/ProgrammingPro-ness May 28 '19

MomentJS has made me so happy over the years.

4

u/DasDoto May 29 '19

I use date-fns these days over moment. You can import only the function you need and the dates are immutable unlike moment. A lot lighter than moment as well.

3

u/ModernCannabist May 29 '19

We just switched to DayJS because it does everything MomentJS does but at about the quarter the size