OpenViSTAI · Agents · Blockchain · Crypto
Menu

OPENVIST LEARN · FREE LESSONS

Objects, fields and own properties

Use named fields without confusing a missing value with an inherited property.

Lesson 9 of 25 · About 20 minutes · Beginner · English

By the end of this lesson

Read a record and validate its own keys.

Before you start

  • Node.js 24 with a terminal and plain-text editor; the browser-only lesson is labelled separately.
  • Complete lesson 8 or be comfortable with its examples.

Three words to know

Property
A named value associated with an object.
Own property
A property stored directly on an object.
Prototype
Another object used for inherited property lookup.

1. A record has named fields

Objects are useful when a value belongs to a named field. Dot notation uses a fixed property name; brackets can use a name stored in a variable. Property access does not validate a record.

Read a recordJAVASCRIPT · Node.js · save as lesson.mjs
const task = { title: "Read", status: "open" };
const field = "status";
console.log(task.title);
console.log(task[field]);
What you should see · example output
Read
open

2. Missing and present are different

Object.hasOwn checks a property stored directly on the object. Reading a missing property returns undefined, but a property can also explicitly contain undefined. The in operator includes inherited properties, which is not the rule we want for validating JSON fields.

Check presence preciselyJAVASCRIPT · Node.js · save as lesson.mjs
const record = { status: undefined };
console.log(Object.hasOwn(record, "status"));
console.log(Object.hasOwn(record, "title"));
console.log(Object.hasOwn(record, "toString"));
What you should see · example output
true
false
false

3. Validate before treating external data as a record

typeof null and typeof [] both return object. Reject null and arrays when the format expects an ordinary record, then check Object.keys and the required value types. Do not merge unknown keys into configuration objects merely because JSON parsed successfully. Dynamic dictionaries are often clearer as a Map.

Inspect exact keysJAVASCRIPT · Node.js · save as lesson.mjs
const record = { title: "Read", status: "open" };
console.log(Object.keys(record).sort().join(","));
What you should see · example output
status,title

YOUR TURN

A small check before you continue

Why is typeof value === "object" not enough to validate a task record?

Show a suggested answer

It includes null and arrays and says nothing about required keys or their types. Validate each of those conditions explicitly.

Sources and scope

Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.