Skip to content

Incorrect information about objects and arrays #187

Open
@NVedsted

Description

@NVedsted

The README for JS1 week 3 alleges that JavaScript has special handling for accessing numerical properties. This is not the case. An array is an object with properties for each index thus it does not differentiate between indexes or properties.

I regret looking into this as it kinda seems it converts indexes to string and looks up the property based on that. Knowledge I would rather have been without. 😅

One can do a quick experiment to see this:

const arr = ["apple", "pear", "orange"];
console.log(JSON.stringify(Object.getOwnPropertyDescriptors(arr)))

which yields:

{
    "0": {
        "value": "apple",
        "writable": true,
        "enumerable": true,
        "configurable": true
    },
    "1": {
        "value": "pear",
        "writable": true,
        "enumerable": true,
        "configurable": true
    },
    "2": {
        "value": "orange",
        "writable": true,
        "enumerable": true,
        "configurable": true
    },
    "length": {
        "value": 3,
        "writable": true,
        "enumerable": false,
        "configurable": false
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions