Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8532825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:48:21+00:00 2026-06-11T09:48:21+00:00

A for – in loop will go through all enumerable properties of an object,

  • 0

A for–in loop will go through all enumerable properties of an object, even those in the prototype chain. The function hasOwnProperty can filter out those enumerable properties that are in the prototype chain. Finally, the function propertyIsEnumerable can discriminate the enumerable properties of an object.

Therefore, the following script should not print anything:

for(a in window)
    if(window.hasOwnProperty(a) && !window.propertyIsEnumerable(a))
        console.log(a);

On Chrome, however, the above prints a lot of property names.

Why do the for–in loop and propertyIsEnumerable contradict each other regarding enumerables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:48:22+00:00Added an answer on June 11, 2026 at 9:48 am

    The sad fact is that JavaScript engines are not the same. While ES5 conforming engines will dutifully respect the enumerability of their properties, window is a host object, as pointed out by pimvdb and Felix above, and not beholden to the rules of ES5.

    You can see more evidence of what window object actually is in window.constructor, which will show it as being constructed from

    function Window() { [native code] }
    

    As such, we have no real way of determining why certain properties are enumerable (according to Chrome), and others are not from within the JavaScript runtime.

    However, you can still see the full state of Chrome’s inconsistent window enumerable properties by looking at Object.keys(window) which according to its MDN article, “returns an array of all own enumerable properties found upon a given object.”

    Doing so still returns an array of 30-odd properties. Chalk it up to Chrome strangeness!

    EDIT: With some further testing, I found the proper way for Chrome to make sense as to window‘s enumerable properties

    Object.keys(window).filter(function(prop) {
      return window.hasOwnProperty(prop) && !window.propertyIsEnumerable(prop);
    });
    

    It would seem that in Chrome, the candidate list of properties for enumeration by for...in is NOT what is returned by Object.keys, but actually much closer to Object.getOwnPropertyNames which lists enumerable and non-enumerable properties. However, even that is inconsistent. The list of properties that are window.hasOwnProperty(prop) && !window.propertyIsEnumerable(prop) come out to 423 and 454 for for...in and Object.getOwnPropertyNames, respectively, in my testing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
Have a webpage that will be viewed by mainly IE users, so CSS3 is
I am reading some og tags from sites but I can't seem to decode
Possible Duplicate: replace all occurrences in a string I found this question/answer: Use JavaScript
My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
I was beta-testing my iPhone App (not through xcode), and the app crashed. I
I would like to count the length of a string with PHP. The string
I've got the following login script.. <?php $name = $_POST[name]; $password = $_POST[password]; $query
So to start, I have an array of XML files. These files need to
I'm struggling to position the second level of a dropdown nav menu and was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.