Objects of "Object" Data Type

This section provides a quick description of the 'Object' data type, its properties and methods. A tutorial example is provided on how to create and test an object of the 'Object' data type.

To learn how to use objects in JavaScript, we need to start with the "Object" data type, which has the following basic features:

Here is tutorial example showing some of those properties and methods defined on "Object" data type:

<html>
<!-- Object_Object.html
   Copyright (c) 2008 HerongYang.com. All Rights Reserved.
-->
<head>
<title>Objects of "Object"</title>
</head>
<body>
<pre>
<script type="text/javascript">

   // Creating an object and assigning it to a variable
   var mySite = new Object();
   
   // Showing the built-in properties
   document.writeln('mySite.constructor: '+mySite.constructor); 
   document.writeln('mySite.prototype: '+mySite.prototype); 

   // Adding a property this object only
   mySite.name = "herongyang.com";

   // Converting this object to a string
   document.writeln('mySite.toString(): '+mySite.toString()); 

   // Converting this object to a numeric value
   document.writeln('mySite.valueOf(): '+mySite.valueOf());
   
   // Testing a property of this object
   document.writeln('mySite.hasOwnProperty("name"): '
      +mySite.hasOwnProperty("name"));
   document.writeln('mySite.hasOwnProperty("constructor"): '
      +mySite.hasOwnProperty("constructor"));
   document.writeln('mySite.hasOwnProperty("address"): '
      +mySite.hasOwnProperty("address"));
</script>
</pre>
</body>
</html>

Run this example, you will get this interesting result:

mySite.constructor: 
function Object() {
    [native code]
}

mySite.prototype: undefined
mySite.toString(): [object Object]
mySite.valueOf(): [object Object]
mySite.hasOwnProperty("name"): true
mySite.hasOwnProperty("constructor"): false
mySite.hasOwnProperty("address"): false

Explanation of this result will be provided in next sections.

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

 What Is an Object?

Objects of "Object" Data Type

 Adding and Deleting Object Own Properties

 Adding and Deleting Object Own Methods

 Using "this" Keyword to Represent Current Object

 Object Literals of the "Object" Type

 Objects and Associate Arrays

 Objects with Indexed Properties

 Differences between "Object" and "Array"

 Using "Array" Objects as "Object" 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

 W3C's Document Object Model (DOM) Specifications

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB