The Object() constructor called as a function
the basics
WHEN passing no argument to Object() THEN a new empty object is returned
WHEN passing null THEN a new empty object is returned
WHEN passing undefined THEN a new empty object is returned
calling it with a complex type (or non-primitive)
WHEN passing an existing (empty) object THEN that same object is returned
WHEN passing an array THEN that same array is returned (because it is also "just" an object)
calling it with a primitive
WHEN calling it with true THEN it returns a new instance of a Boolean just like new Boolean(true) would
WHEN calling it with 42 THEN it returns a new instance of a Number just like new Number(42) would
WHEN calling it with a string THEN it returns a new instance of a String just like new String("abc") would
Links
The first version of the spec already has the `ToObject` (see section 9.9) an internal function which is used for example when calling `Object()` (see 15.2.1.1). (PDF 732kB).
The MDN pages describing this function, easy to read with examples.
Related Katas
Global Object API
Object API
Object()(as introduced in ES1)Object.is()Object.fromEntries()Object.fromEntries()in depthObject.groupBy()
Object literal
Difficulty Level
INTERMEDIATE
First Published
27 March 2024
Stats
8 tests to solve