Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

3. Object() > Object() Parameters

Object() Parameters

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.

Live Code

<!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.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint