JS: Object Type
What is object
A JavaScript object is one of the Value Types.
JavaScript spec defines object as: “a collection of key-and-value pairs”. (each pair is called a Property of the object.)
For example, the following are all objects: array, function, date, regex.
Test if a value is object type
Data object (object object)
The data object, e.g.
{a:1, b:2}
, is the best example of a collection of key-and-value pairs.
We often call this
data object
or just
object.
JavaScript spec calls it
object object.
Special purpose objects
All objects other than the “data object” have special purposes and or hold internal data for that purpose.
For example, array, function, date, regex.
For many more, see
You can add properties to any value of object type
You can add properties to function, date, regexp, etc., even though they are not usually used for holding data.
// example of adding properties to different objects let xx; // array xx = [3, 4]; xx.cats = 2; console.log(xx); // [ 3, 4, cats: 2 ] // s------------------------------ // arrow function xx = () => 3; xx.cats = 2; console.log(xx); // [Function: xx] { cats: 2 } // s------------------------------ // date xx = new Date(); xx.cats = 2; console.log(xx); // 2026-01-18T07:16:41.722Z { cats: 2 } // s------------------------------ // RegExp xx = /\d+/; xx.cats = 2; console.log(xx); // /\d+/ { cats: 2 }