JavaScript Month Days Trick
getting the number of days in a month in js is kinda funny new Date( year, month, 0 ).getDate() two hidden off-by-ones are working in our favor: • month 1 is actually february • day 1 is the first day, so day 0 is the last day of the previous month :3c
A dark-mode social media post explains a JavaScript trick for finding the number of days in a month using `new Date(year, month, 0).getDate()`. The joke is that two confusing off-by-one behaviors—zero-based months and day zero referring to the previous month’s last day—happen to make the code work. It is shared as a humorous reaction by programmers who recognize JavaScript’s quirky date handling. EN: A dark-mode social media post explains a JavaScript trick for finding the number of days in a month using `new Date(year, month, 0).getDate()`. The joke is that two confusing off-by-one behaviors—zero-based months and day zero referring to the previous month’s last day—happen to make the code work. It is shared as a humorous reaction by programmers who recognize JavaScript’s quirky date handling.
- @rzeczyzabawne / 17223 2024-07-02
- Template
- Programming tweet screenshot
- Type
- image
- Size
- 800×649 · 63.0 KiB
- Mood
- nerdy, amused
- Language
- en
- Added