There is no issue in javascript function.
In Javascript months start with 0 to 11, if you pass 0 will return January and 11 will return december.
Somehow JavaScript returning January during insertion of 12 month in digit instead of error but you achieved your result by 0 to 11 month.
Here is code for your reference.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript new Date()</h2>
<p>5 numbers specify year, month, day, hour, and minute:</p>
<p id="demo"></p>
<p id="demo1"></p>
<script>
var d = new Date(2018, 0, 24, 10, 33);
document.getElementById("demo").innerHTML = d;
var d1 = new Date(2018, 11, 24, 10, 33)
document.getElementById("demo1").innerHTML = d1;
</script>
</body>
</html>