javascriptjavascript-objectsnested-object

Working with nested objects. What do 'car', 'inside', and 'outside' specify here


const myStorage = {
            'car': {
                'inside': {
                    'glove box': 'maps',
                    'passenger seat': 'crumbs'
                },
                'outside': {
                    'trunk': 'jack'
                }
            }
        };

I can understand 'glove box' is the property and its value is 'maps', but what about 'car', 'inside' and 'outside'. Are they also properties or the values of car? I can recognise with a comma that we have two objects here, but where do these start. Please elaborate on this.


Solution

  • myStorage is an object with the property car. car is also an object with two properties, inside and outside

    Properties are the values associated with a JavaScript object.

    A JavaScript object is a collection of unordered properties.

    So in this case, car is both an object (data type) and a property (value associated with myStorage)

    I'd recommend reading up on JavaScript data structures: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures