Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect information about objects and arrays #187

Open
NVedsted opened this issue Nov 30, 2024 · 0 comments
Open

Incorrect information about objects and arrays #187

NVedsted opened this issue Nov 30, 2024 · 0 comments

Comments

@NVedsted
Copy link

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
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant