Unsual working of Date() method in Javascript

34 views Asked by At
const mydate = new Date('2023,1,18');
console.log(mydate.toDateString());

This code results in

Wed Jan 18 2023

whereas

const mydate = new Date(2023, 0, 18);
console.log(mydate.toDateString());

also gives an output

Wed Jan 18 2023

But

const mydate = new Date('2023,0,18');
console.log(mydate.toDateString());

is invalid for this case why?

0

There are 0 answers