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 6368871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:43:50+00:00 2026-05-25T00:43:50+00:00

I am working an a basic learning script below. My main question is in

  • 0

I am working an a basic learning script below. My main question is in the for() declaration what is the ‘IN’ reserved word and how does the starName relate to it because it is not defined anywhere earlier on the page.

I am trying to understand how the for() loop is “thinking” with that starName in star statement.

<script type="text/javascript">
var star = {};

star["Polaris"] = new Object;
star["Mizar"] = new Object;
star["Aldebaran"] = new Object;
star["Rigel"] = new Object;

star["Polaris"].constellation = "Ursa Minor";
star["Mizar"].constellation = "Ursa Major";
star["Aldebaran"].constellation = "Taurus";
star["Rigel"].constellation = "Orion";

</script>
</head>
<body id="mainbody">

<script type="text/javascript">
for (starName in star) {
var para = document.createElement('p');
para.id = starName;
para.appendChild(document.createTextNode(starName +
": " + star[starName].constellation));
document.getElementsByTagName("body")[0].appendChild(para);
}
</script>

<!-- output below -->

<p id="Polaris">Polaris: Ursa Minor</p>
<p id="Mizar">Mizar: Ursa Major</p>
<p id="Aldebaran">Aldebaran: Taurus</p>
<p id="Rigel">Rigel: Orion</p>
  • 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-05-25T00:43:51+00:00Added an answer on May 25, 2026 at 12:43 am

    The for ... in syntax enumerates all enumerable properties of an object.

    starName will be a string that represents the name of the property. You can that access that property (and do plenty of other things) like that:

    var p = star[starName];
    

    Now there are a couple things you should be aware of when using the for ... in syntax:

    Make use of hasOwnProperty to safeguard against properties added higher in the prototype chain.

    Object.prototype.allObjectWillInheritThis = 1;
    
    /// ...
    
    for (var starName in star) {
        if (star.hasOwnProperty(starName)) {
    
            // Do your thing
        }
    }
    

    Filter out functions. Chances are you are not interested in function but in properties.

    for (var starName in star) {
        if (star.hasOwnProperty(starName) &&
            typeof star[starName] !== 'function') {
    
            // Do your thing
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really basic question. Learning Django and now working on development server with nginx set
I just started learning Zend. I managed to get the basic working (using zf
I'm learning web2py 1.98.2, so the question is very basic. In static/css folder I
I have a service, as follows: The most basic (working) CherryPy 3.1 Windows service
I am working in Visual Basic 6 and need to sort by multiple columns
I am working on a basic Struts based application that is experience major spikes
I'm working on a basic Issue Management System in order to learn ASP.NET MVC.
I'm working on a basic google applications based system. Like I earlier defined I'm
I'm working on a basic garden logging application which consists of gardens, plants and
I'm working on a basic DBMS as a pet project and planning to prototype

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.