MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/btxz72/what_are_some_javascript_things_beginners_dont/ep6at9n/?context=3
r/javascript • u/[deleted] • May 28 '19
383 comments sorted by
View all comments
247
Months are zero based
47 u/inu-no-policemen May 28 '19 This allows you to use the month as an index:> ['jan', 'feb', 'mar', 'apr', 'may', 'etc'][new Date().getMonth()] "may"It probably sounded like a good idea at the time.Anyhow, that's why it is that way. This behavior isn't unique to JS either. 28 u/StoneCypher May 28 '19 Much better to use the locale API.const month = date.toLocaleString('en-us', { month: 'short' });
47
This allows you to use the month as an index:
> ['jan', 'feb', 'mar', 'apr', 'may', 'etc'][new Date().getMonth()] "may"
It probably sounded like a good idea at the time.
Anyhow, that's why it is that way. This behavior isn't unique to JS either.
28 u/StoneCypher May 28 '19 Much better to use the locale API.const month = date.toLocaleString('en-us', { month: 'short' });
28
Much better to use the locale API.
const month = date.toLocaleString('en-us', { month: 'short' });
247
u/TrikkyMakk May 28 '19
Months are zero based