Computer >> Computer tutorials >  >> Programming >> Javascript

How to create object properties in JavaScript?


Object properties can be any of the three primitive data types, or any of the abstract data types, such as another object. Object properties are usually variables used internally in the object's methods, but can also be globally visible variables that are used throughout the page.

The syntax for adding a property to an object is −

objectName.objectProperty = propertyValue;

The following code gets the document title using the "title" property of the “document” object −

var str = document.title;