Created
February 25, 2026 19:18
-
-
Save petergi/e9858f7d96ffc70552e16387bb577b9a to your computer and use it in GitHub Desktop.
Checks if the given date is a weekend.
- Use `Date.prototype.getDay()` to check weekend by using a modulo operator (`%`).
- Omit the argument, `d`, to use the current date as default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks if the given date is a weekend. | |
| // - Use `Date.prototype.getDay()` to check weekend by using a modulo operator (`%`). | |
| // - Omit the argument, `d`, to use the current date as default. | |
| const isWeekend = (d = new Date()) => d.getDay() % 6 === 0; | |
| isWeekend(); // 2018-10-19 (if current date is 2018-10-18) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment