Skip to content

Update index.md #39921

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Update index.md #39921

wants to merge 3 commits into from

Conversation

blmatthews
Copy link

In the "Problematic cases for hasOwnProperty" section, show how hasOwnProperty operates in the two cases as well as Object.hasOwn, and correct the expected output of the Object.hasOwn examples (it was logging the property value, which wouldn't result in true or false. Modified it to just log the Object.hasOwn result).

Description

Make clearer how hasOwnProperty works in the two cases and make it easy to compare with Object.hasOwn. Also correct the expected output of the console.logs in the Object.hasOwn cases.

Motivation

Makes the difference between Object.hasOwn and hasOwnProperty clearer by having them in the same example, and fix the expected output in the Object.hasOwn cases.

Additional details

Related issues and pull requests

I was going to create an issue but it directed me to do this, so I did. Should I still create an issue, or is this sufficient?

In the "Problematic cases for hasOwnProperty" section, show how hasOwnProperty operates in the two cases as well as Object.hasOwn, and correct the expected output of the Object.hasOwn examples (it was logging the property value, which wouldn't result in true or false. Modified it to just log the Object.hasOwn result).
@blmatthews blmatthews requested a review from a team as a code owner June 12, 2025 17:36
@blmatthews blmatthews requested review from Josh-Cena and removed request for a team June 12, 2025 17:36
@github-actions github-actions bot added Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed labels Jun 12, 2025
Comment on lines 162 to 163
console.log(foo.hasOwnProperty("prop")) // Uncaught TypeError: foo.hasOwnProperty is not a function
// hasOwnProperty is on the prototype chain, which foo doesn't have
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[mdn-linter] reported by reviewdog 🐶

Suggested change
console.log(foo.hasOwnProperty("prop")) // Uncaught TypeError: foo.hasOwnProperty is not a function
// hasOwnProperty is on the prototype chain, which foo doesn't have
console.log(foo.hasOwnProperty("prop")); // Uncaught TypeError: foo.hasOwnProperty is not a function
// hasOwnProperty is on the prototype chain, which foo doesn't have

Copy link
Author

@blmatthews blmatthews Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer if the comments line up, and as it's in a <pre> section indenting with spaces should be fine, so I'd like to leave it as I committed it, but happy to change it if you disagree.

…own/index.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

github-actions bot commented Jun 12, 2025

Preview URLs

(comment last updated: 2025-06-13 04:31:24)

The comments wrap on the preview page so might as well combine the indented one with the one on the previous line. Also, missing a ; and a C where there should have been a c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant