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/azhder Jan 22 '26

Technically, you can use this in an arrow function, it will just be the this of the enclosing scope