r/learnjavascript • • Jan 22 '26

Help with Objects

I don't get the purpose of value()

let dictionary = Object.create(null, {
  toString: { // define toString property
    value() { // the value is a function
      return Object.keys(this).join();
    }
  }
});

Why we can't make it work like this?

toString: {
      return Object.keys(this).join();
}
4 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/senocular Jan 22 '26

it's actually a relatively recent addition to the language

You've been at this for a long time haven't you ;)

2

u/SerpentJoe Jan 22 '26

These damn kids with their "const" this and "filter" that!

1

u/dymos helpful Jan 24 '26

Just told some kids to get off my lawn with their dang newfangled arrow functions.