I just started learning Javascript and currently, I am following the Javascript Crash course for Beginners by Traversy Media on Youtube. (https://www.youtube.com/watch?v=hdI2bqOjy3c - I am at 1:02:00)
I am following his example with Constructor Function, but I get a different result on the console from the one he gets and (probably because I am just a beginner) I don't understand why.
The code is:
function Person(firstName, surname, dob) {
this.firsName = firstName;
this.surname = surname;
this.dob = new Date(dob);
};
const person1 = new Person('Mike', 'Smith', '5-6-1990');
const person2 = new Person('Lisa', 'Gregory', '3-6-1970');
console.log(person2.dob);
now, why do I get Invalid Date
while he gets Fri Mar 06 1970 00:00:00 GMT-0500 (Eastern Standard Time)
?
Am I doing something wrong?