Overview of objects

JavaScript allows many types of data to be treated as if they were objects, such as Booleans, numbers, and strings. Following best practice, we will not treat them as objects, other than to use their methods.

Objects in JavaScript

Some built-in objects in JavaScript, of varying importance, are briefly introduced here.

Object Information Example methods
Date Date and time Extract or set the month
Math Mathematical functions Determine the floor of a value
Canvas Drawings of pictures Draw lines and shapes of specified colours
Document Object Model Components of the web page Extract and modify parts
Regular expressions Text patterns Match and modify matched text

Syntax for properties and methods

Since they can be viewed as objects, data such as numbers and strings have propertiesA slot for one of the values bundled in an object. (though null and undefined do not). For example, the length property of a string gives the number of characters in the string.

You can use dot notationSyntax for a function call in which the first input is followed by a period and then the name of the function, with any additional inputs following in parentheses, separated by commas. to access a property, here shown for an object with identifier myObject that has a property with the name someProperty.

myObject.someProperty

Two alternative methods are listed below. In the second example the expression evaluates to a string, where the string is the name of a property.

myObject["someProperty"]

myObject[expression]

Dot notationSyntax for a function call in which the first input is followed by a period and then the name of the function, with any additional inputs following in parentheses, separated by commas. is used to call a methodA function associated with a class.. All objects have the methods .valueOf() and .toString(), which can be called as follows:

myObject.valueOf();  
myObject.toString();

Roughly speaking, .valueOf() produces the value of an object, such as a number for a number and a string for a string, and .toString() produces the string equivalent of the object.