Object constructor JS Home  <<  JS Reference  <<  Object

In JavaScript you create an object instance using the constructor Object.

Description

Creates an Object wrapper.

Syntax

Signature Description
var anObject = new Object([value]);Creates an Object wrapper.

Parameters

Parameter Description
valueAn optional initial value for the object.
  • Creates an Object wrapper for the given value if specified
  • If given value null or undefined creates an empty object.

Class Properties

Class Property Description
prototypeEnables property assignment to objects of type Object and is inherited by every object.

Instance Properties

Instance Property Description
constructorReturns a reference to the function that created the prototype and is inherited by every object.

Class Methods

None.

Instance Methods

Instance Method Description
Getter (Accessor) MethodsThese methods DO NOT modify the Object object
Methods of the Object class, all of which are inherited by every object via prototype.
hasOwnProperty()Returns a boolean indicating whether the object has the specified direct property.
isPrototypeOf()Returns a boolean indicating whether the object exists in another objects hierarchy.
toLocaleString()Returns a string representation of an object.
toString()Returns a string representation of an object.
valueOf()Returns the primitive value of the specified object.
Setter (Mutator) MethodsThese methods DO modify the Object object
None.

Examples

The code below creates an object with some properties.



/*
 Create an object that holds first and last name properties
 */
var homeOwner = new Object();
homeOwner.firstName = 'Teddy';
homeOwner.lastName = 'Bear';
alert(homeOwner.firstName + ' ' + homeOwner.lastName);

/*
 We could just as easily assign the surname property with a typo as below 
 and then scratched our heads when we tried to access the nameStore.lastName 
 property. Be careful what you type when assigning object properties
 */
homeOwner.lastNaem = Bear;

Press the button below to action the above code:

Related Tutorials

JavaScript Basic Tutorials - Lesson 7 - Objects

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Object

Class Properties
prototype
Instance Properties
constructor
Class Methods
None.
Instance Methods Getters
hasOwnProperty()
isPrototypeOf()
toLocaleString()
toString()
valueOf()
Instance Methods Setters
None.

Statements

Operators