Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

364
Views
Why does calling Object.getOwnPropertyDescriptors on a date object return an empty array?

I'm trying to understand how JavaScript objects work fully. I know that when you call Object.getOwnPropertyDescriptors on an object, you get an object containing the descriptors. For example, if you defined your own object, and got the descriptors, you would get something like this:

let foo = {
  bar: 2
}

Object.getOwnPropertyDescriptors(foo);
// Output: 
// {
//   bar: {
//     value: 2,
//     writable: true,
//     enumerable: true,
//     configurable: true,
//   }
// }

Likewise, if you get the descriptors on a built-in object, e.g. like an Error, you can see the descriptors of the error object.

let foo = new Error();

Object.getOwnPropertyDescriptors(foo);
// Output: 
// {
//   bar: {
//     value: 'Error\n    at <anonymous>:1:11',
//     writable: true,
//     enumerable: false,
//     configurable: true,
//   }
// }

I understand that the property was created when the Error constructor was called. Everything that I've just stated makes sense to me. However, when I try to get the descriptors of a date object, nothing is returned.

let foo = new Date();

Object.getOwnPropertyDescriptors(foo);
// Output: 
// {}

I can get the value of the date as a string just by accessing it, but why is there not a descriptor for the value?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Date objects are not said to contain any own-properties. Per the spec:

21.4.5 Properties of Date Instances

Date instances are ordinary objects that inherit properties from the Date prototype object. Date instances also have a [[DateValue]] internal slot. The [[DateValue]] internal slot is the time value represented by this Date.

And that's it.

All the information contained for a given Date is within that [[DateValue]] internal slot, which is not exposed directly via JavaScript - it's accessed and manipulated only through the methods on Date.prototype, the object that date instances inherit from.

I can get the value of the date as a string just by accessing it

This works because you'd be calling the toString method which exists on the prototype. For example:

const proto = {
  toString() {
    return 'foo';
  }
};
const instance = Object.create(proto);
console.log(instance.toString());
console.log(Object.getOwnPropertyDescriptors(instance));

The object can have toString called on it without having any properties directly on the instance.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!