The "Object" Object Type - The Root Object Type

This section provides a quick description and a tutorial example script of the 'Object' built-in object type, which is the root or base object type of all other object types.

The "Object" object type is probably the most important built-in object type. It has the following main features:

Here is a tutorial sample script showing you some of those features:

// Object_Object_Type.js
// Copyright (c) 2013 HerongYang.com. All Rights Reserved.

   // Creating an object of the "Object" object type
   var myObject = new Object();

   // Adding properties to the object
   myObject.name = "Unknown";
   myObject.size = "1.71m";
   myObject.weight = "65kg";

   // Checking the object
   println("About the myObject:");
   println("   Type: "+(typeof myObject));
   println("   Instance Of Object: "+(myObject instanceof Object));
   println("   Properties:");
   for (var item in myObject) {
      println("      "+item+": "+myObject[item]);
   }

   // Creating an object of the "Book" object type
   var myBook = new Book("JavaScript Tutorial", "Herong Yang");

   // Checking the object
   println("About the myBook:");
   println("   Type: "+(typeof myBook));
   println("   Instance Of Object: "+(myBook instanceof Object));
   println("   Instance Of Book: "+(myBook instanceof Book));
   println("   Properties:");
   for (var item in myBook) {
      println("      "+item+": "+myBook[item]);
   }

// Defining the constructor for a new object type
function Book(title, author) {
   this.title = title;
   this.author = author;
}

If you run this script with "jrunscript", you will get:

About the myObject:
   Type: object
   Instance Of Object: true
   Properties:
      weight: 65kg
      name: Unknown
      size: 1.71m

About the myBook:
   Type: object
   Instance Of Object: true
   Instance Of Book: true
   Properties:
      title: JavaScript Tutorial
      author: Herong Yang

"myBook" is an instance of "Book" and "Object", because "Book" is sub type of "Object" by default.

Read other "Object" related chapters to see more tutorial examples.

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

Introduction to Built-in Object Types

 Overview of Built-in Object Types

The "Object" Object Type - The Root Object Type

 The "Global" Object Type - The Invisible Global Container

 Global Properties and Functions Defined in ECMAScript

 Global Properties and Functions Provided by "jrunscript"

 The "Function" Object Type - Functions Are Objects

 The "Array" Object Type - Arrays Are Objects

 The "JSON" Object Type - parse() and stringify()

 The "String" Object Type - Not Equal to String Primitive Type

 The "Boolean" Object Type - Wrapping Boolean Values into Objects

 The "Number" Object Type - Not Equal to Number Primitive Type

 The "Date" Object Type - Managing Dates and Times

 The "RegExp" Object Type - Regular Expression Patterns

 The "Error" Object Type - Runtime Exceptions

 The "Math" Object Type - The Math Container

 W3C's Document Object Model (DOM) Specifications

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB