Javascript Object Reference Type

Introduction

Objects in Javascript are created by new operator followed by the name of the object type.

Developers create their own objects by creating instances of the Object type and adding properties and/or methods to it:

let o = new Object(); 

If there are no arguments, as in the following example, then the parentheses can be omitted:

let o = new Object;  // legal, but not recommended 

The Object type in Javascript is the base from which all other objects are derived.

All of the properties and methods of the Object type are present on other, more specific objects.

Each Object instance has the following properties and methods:

Properties/Method Description
constructor function that was used to create the object.
hasOwnProperty(propertyName) Indicates if the given property exists on the object instance, not on the prototype. The property name must be specified as a string.
isPrototypeof(object) Determines if the object is a prototype of another object.
propertyIsEnumerable(propertyName) Indicates if the given property can be enumerated using the for-in statement. The property name must be a string.
toLocaleString()Returns a string representation of the object that is appropriate for the locale of execution environment.
toString() Returns a string representation of the object.
valueOf() Returns a string, number, or Boolean equivalent of the object. It often returns the same value as toString().



PreviousNext

Related