r/javascript • • May 28 '19

What are some JavaScript things beginners don't know?

333 Upvotes

383 comments sorted by

View all comments

247

u/TrikkyMakk May 28 '19

Months are zero based

0

u/[deleted] May 28 '19

[deleted]

34

u/Careerier May 28 '19

This is true, but that's something even beginners (hopefully) should know.

The date thing is weird because months start at zero, but days, hours, seconds, and milliseconds start at 1.

new Date(2019, 1, 1, 1, 1, 1) gives you Fri Feb 01 2019 01:01:01

3

u/the_php_coder May 28 '19

Not in the latest version of node LTS apparently. I just tried and I got jan instead of feb:

> new Date(2019, 1, 1, 1, 1, 1);
2019-01-31T19:31:01.000Z

3

u/yitianjian May 28 '19

Did you get January 31?

→ More replies (3)