Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Objects > Properties

Properties

The most important part of an object are its properties. The sections that follow explain them in detail.

Querying and Setting Properties

To obtain the value of a property, you can use the dot (.) or square bracket ([]) operators described in Property Access. The left-hand side should be an expression whose value is an object. If using the dot operator, the right-hand must be a simple identifier that names the property. If using square brackets, the value within the brackets must be an expression that evaluates to a string (or number) that contains the desired property name:

// Get the "author" property of the book.
var author = book.author;      
// Get the "surname" property of the author.
var name = author.surname      
// Get the "main title" property of the book.
var title = book["main title"]

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial