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
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
- Node.js, to run the example. Install it from the Node.js download page (opens in a new tab).
The Example
An object for a book with two properties, title and pages, in a file named book.js.
Step 1: Write the Code
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
node book.js
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
| Mistake | What happens | Do this instead |
|---|---|---|
Different capitals, such as book.Title | You get undefined, because Title and title are different names | Write 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
- Property accessors (opens in a new tab) (MDN)
- Working with objects (opens in a new tab) (MDN)
- Run Node.js scripts from the command line (opens in a new tab) (Node.js docs)
JavaScript is a trademark of Oracle Corporation in the United States. Node.js is a trademark of the OpenJS Foundation.
0 comments