MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/btxz72/what_are_some_javascript_things_beginners_dont/ep4jnep/?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' }); 44 u/NotSamNub May 28 '19 Ah, out of the 6 months in the year, my favourite has to be "etc", such lovely weather during that time of year! 0 u/[deleted] May 28 '19 [deleted] 10 u/TyrionReynolds May 28 '19 Lousy Smarch weather. → More replies (1) → More replies (24)
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' }); 44 u/NotSamNub May 28 '19 Ah, out of the 6 months in the year, my favourite has to be "etc", such lovely weather during that time of year! 0 u/[deleted] May 28 '19 [deleted] 10 u/TyrionReynolds May 28 '19 Lousy Smarch weather. → More replies (1)
28
Much better to use the locale API.
const month = date.toLocaleString('en-us', { month: 'short' });
44
Ah, out of the 6 months in the year, my favourite has to be "etc", such lovely weather during that time of year!
0 u/[deleted] May 28 '19 [deleted] 10 u/TyrionReynolds May 28 '19 Lousy Smarch weather. → More replies (1)
0
[deleted]
10 u/TyrionReynolds May 28 '19 Lousy Smarch weather. → More replies (1)
10
Lousy Smarch weather.
→ More replies (1)
247
u/TrikkyMakk May 28 '19
Months are zero based