In this blog post, we get the last day of a given month in javascript.
Creates a JavaScript Date
instance that represents a single moment in time in a platform-independent format. Date
objects contain a Number
that represents milliseconds since 1 January 1970 UTC.
Javascript
<script>
var month = 1; // January
var d = new Date(2021, month, 0);
console.log(d.toString()); // last day in January
</script>
Result
Sun Jan 31 2021 00:00:00 GMT+0530 (India Standard Time)
Syntax
new Date()
new Date(value)
new Date(dateString)
new Date(dateObject)
new Date(year, monthIndex)
new Date(year, monthIndex, day)
new Date(year, monthIndex, day, hours)
new Date(year, monthIndex, day, hours, minutes)
new Date(year, monthIndex, day, hours, minutes, seconds)
new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds)
I hope it will help you.

Brijpal Sharma is a web developer with a passion for writing tech tutorials. Learn JavaScript and other web development technology.