Tutorial — Objects

Core JavaScript consists of nine types of object:

All objects inherit from the basic JavaScript Object, so all objects inherit Object's Properties. For example, all objects inherit the toString() method.

In other contexts, such as an Internet Browser or Siebel Software, there may be other object types available. For example, Browsers have a document and Siebel had TheApplication().

You create a new object with the new keyword:

var  obj = new Object(); // new Object

var  str1 = new String(); // new String (empty)
var  str2 = new String("Hello"); // new String (with a value)

Some object types allow a short-cut form of creation that allows you to omit the new keyword:

var  str1 = new String("Hello"); // new String (with a value)
var  str2 = "Hello"; // same effect

var  n1 = new Number(42); // new Number (with a value)
var  n2 = 42; // same effect

The difference is that when you use new the object is of type object (because new creates a new Object). Variables that are assigned literals have typeof the literal.