Site icon JD Bots

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

Syntax

object.property

See Property accessors 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.js

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

Terminal

node book.js

Output

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.

Exit mobile version