1

I've seen a number of questions about new Object vs new Object() or new Object() vs {}, but I'm wondering about what the difference is between Object() and new Object()? In other words, what's the difference between calling the Object constructor with new vs not?

I've seen one other answer here on StackOverflow, but it's in regards to ES5. I'm wondering about for ES6?

I also ask because MDN on their page for the Object() constructor states:

Note: Object() can be called with or without new, but sometimes with different effects. See Return value.

But under the "Return value" section on that page, I cannot discern what these "different effects" may be?

mishar
  • 89
  • 6
  • 2
    This did not change with ES6 afaik. I'm tempted to close the question as a duplicate. – Bergi Aug 27 '23 at 21:32
  • At best, they removed the section about special-casing host objects that no implementation was actually using. Did you check the ES6 spec yourself already? – Bergi Aug 27 '23 at 21:33
  • "*I cannot discern what these "different effects" may be?*" - probably those that are mentioned in [the answer](https://stackoverflow.com/a/30805762/1048572) to the question you linked - which are none in practice. – Bergi Aug 27 '23 at 21:34
  • 2
    [According to the current spec](https://tc39.es/ecma262/#sec-object-constructor), the return values are not different — they both result in an _ordinary object_ when invoked without an argument. Prefer neither (unless you're programming functionally) and instead use a new object literal: `const obj = {};`. – jsejcksn Aug 27 '23 at 22:40
  • @Bergi yeah I checked it, but again nothing particularly obvious to me in terms of differences, so I was wondering if there was something I missed, again particularly because MDN seemed to note there was. Also about this being a duplicate, it is ES6, not ES5, in which a number of overhauls were made to JS, so I thought this might be part of one of them. Particularly too [as there was a discussion board](https://esdiscuss.org/topic/new-object-vs-object-difference) linked to by the ES5 question above in which comments about poor and/or outdated wording in the ES5 spec were made. – mishar Aug 27 '23 at 23:00
  • 1
    @mishar In that case, you might want to [post an answer](/help/self-answer) and file an issue for MDN – Bergi Aug 28 '23 at 00:25

0 Answers0