Objects in themselves can be “complex data structures.” This is a direct quote from the MDN page on data structures:
In JavaScript, objects can be seen as a collection of properties. With the object literal syntax, a limited set of properties are initialized; then properties can be added and removed. Property values can be values of any type, including other objects, which enables building complex data structures. Properties are identified using key values. A key value is either a String or a Symbol value.
So an object contains properties, and those properties can be… anything. Boolean, Number, String, Objects, custom Objects, or Arrays of any type. Or hey – functions!
A complex data structure is anything that is not a simple data structure. A Boolean is simple. A String is simple. A Number is simple (whether integer or floating point). Each of these are a one-dimensional data point. An Array can be complex, but doesn’t really have to be – an array of numbers is still numbers.
An Object, however, is usually intended to hold multiple data related points. A Student object, for example:
class Student {
constructor({name, age, school, major, gpa}) {
let newName = name.split(" ");
this._name = {
first: newName[0],
last: newName[1] ? newName[1] : undefined
}
this.age = age;
this.school = school;
this.gpa = gpa;
}
set name(name){
let newName = name.split(" ");
this._name = {
first: newName[0],
last: newName[1] ? newName[1] : undefined
}
}
get name(){
return (this._name.first+" "+this._name.last).trim()
}
}
It is complex because it can contain strings, numbers, booleans, arrays, functions or nested objects. Does it need to? No. But it can, should your need arise.