Core JavaScript consists of nine types of object:
Object
–parent to all othersString
–for working with text values.Boolean
–for working with true/false values.Number
–for working with numeric values.Date
–for working with dates and times.RegExp
–JavaScript has core Regular Expression objects!Array
–a linear array of elements (object references).Function
–even functions are objects in JavaScript!Math
–where all the math methods are kept.
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 Objectvar
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 effectvar
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.
(back) | § | Top | Web | JavaScript | Tutorial |
---|