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:
All "prototype" data types are extended from the "Object" data type.
All objects of all "prototype" data types are inheriting properties and methods from the "Object" data type.
Objects of the "Object" data type can be created with the object initializer operator ({}).
"Object" data type has two properties: "constructor", and "prototype"
"Object" data type has a number of methods: "hasOwnProperty()", "isPrototypeOf()", "toString()", "valueOf()".
Here is tutorial example showing some of those properties and methods defined on "Object" data type:
<html>
<!-- Object_Object.html
Copyright (c) 2008 by Dr. Herong Yang, http://www.herongyang.com/
-->
<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: