Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The Object() constructor function
takes one optional parameter. That parameter is the value you would like
to create. If you provide no parameter, then a null or undefined value will be assumed.
<!DOCTYPE html><html lang="en"><body><script> // create an empty object with no properties var cody1 = new Object(); var cody2 = new Object(undefined); var cody3 = new Object(null); console.log(typeof cody1, typeof cody2, typeof cody3); /* logs 'object object object' */ </script></body></html>
If a value besides null or
undefined is passed to the
Object() constructor, the value passed will be created
as an object. So theoretically, we can use the Object() constructor to create any of the other
native objects that have a constructor. Below, I do just that.