Skip to main content
0 reactions

How to Read an Object Property with Dot Notation in JavaScript

Card titled Dot Notation in JavaScript, labelled JavaScript basics, with four ticked lines: book.title gives Salt and Starlight, book.pages gives 320, and a missing property gives undefined.

A JavaScript object holds values under names called properties. To read one, write the object’s name, a dot and the property’s name: book.title. This is dot notation.

Every command and output on this page is real, run with Node.js 26.13.1 on macOS.

Syntax

SyntaxJavaScript
object.property
  • object: the name of the variable that holds the object.
  • .: the dot that reads a property.
  • property: the property’s name, exactly as it’s written in the object. JavaScript tells capital and small letters apart.

See Property accessors (opens in a new tab) on MDN.

Prerequisites

The Example

An object for a book with two properties, title and pages, in a file named book.js.

Step 1: Write the Code

book.jsJavaScript
const book = { title: 'Salt and Starlight', pages: 320 };

console.log(book.title);
console.log(book.pages);
console.log(book.author);

console.log prints each value on its own line. The last line reads a property the object doesn’t have.

Step 2: Run It

TerminalBash
node book.js
OutputPlain text
Salt and Starlight
320
undefined

book.title and book.pages give the two values. book.author gives undefined, JavaScript’s way of saying the object has no such property.

Common Mistakes

MistakeWhat happensDo this instead
Different capitals, such as book.TitleYou get undefined, because Title and title are different namesWrite the name exactly as it is in the object

FAQ

What does undefined mean here?

That the object has no property with that name. The program doesn’t stop; the read just gives undefined.

Conclusion

Write object.property to read a value. Match the name exactly, and an undefined tells you the property isn’t there.

Additional Resources

JavaScript is a trademark of Oracle Corporation in the United States. Node.js is a trademark of the OpenJS Foundation.

0 comments