2

Reading a previous question about the Date object in JavaScript I pointed out on my notebook the following problem:

var date1 = new Date('2015','02','31');

The command: alert(date1.getDay()); runs correctly!

What happens on my computer with IE and Chrome? If I debug I see:

__proto__ Invalid Date

Why? I also write the command as:

var date1 = new Date(2015, 2, 10);

But the problem continues to be there.

halfer
20.2k20 gold badges111 silver badges208 bronze badges
asked Apr 2, 2015 at 19:02
1
  • If you see an Invalid Date error, you're probably not passing in those values, as they should work ? Commented Apr 2, 2015 at 19:06

1 Answer 1

7

This is not a bug and is entirely expected.

In JavaScript, inheritance is based on objects.

For some reason - the engine designers thought it would be a great idea that the prototypical date - the one every single date object inherits from would be the invalid date. It's the same as Date.prototype. (Read about it here)

All JavaScript objects have (In ES6, also non normative) a __proto__ method that represents what object they inherit from.

What the developer tools is telling you is that your date object inherits from the prototypical date - which is an invalid date. Your date object is just fine.

answered Apr 2, 2015 at 19:09
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.