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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:03:06+00:00 2026-05-15T11:03:06+00:00

Why does for ([] in object); work fine but [void 0 for ([] in

  • 0

Why does for ([] in object); work fine but [void 0 for ([] in object)] or (void 0 for ([] in object)) throw a syntax error for invalid left-hand assignment?

For example, I would expect the following code to work, but it doesn’t (the assertion isn’t even done due to the syntax error):

let (
  i = 0,
  iterable = {__iterator__:function() { var i = 5; while (i--) yield i; } }
) {
  for ([] in iterable) i++;
  console.assertEquals([void 0 for ([] in iterable)].length, i);
}
  • 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-15T11:03:07+00:00Added an answer on May 15, 2026 at 11:03 am

    I did a little digging in jsparse.c of SpiderMonkey (which I assume is the JS parser you’re using for 1.8 features?)

    The [code for (... in ...)] format or generator expression uses a different parse function than the standard for ([] in obj) uses.

    Your LHS error is being created here:
    (jsparse.c line 4200)

    4194           case TOK_LB:
    4195           case TOK_LC:
    4196             pn3 = DestructuringExpr(cx, &data, tc, tt);
    4197             if (!pn3)
    4198                 return NULL;
    4199 
    4200             if (pn3->pn_type != TOK_RB || pn3->pn_count != 2) {
    4201                 js_ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR,
    4202                                             JSMSG_BAD_FOR_LEFTSIDE);
    4203                 return NULL;
    4204             }
    

    When it sees the [ it finds the Destructuring Expression, and ensures the count of the parser node is at 2.

    Interestingly enough [void 0 for ([a,b] in iterator)] should work, although for reasons I don’t care to go digging for, the b from [a,b] is always undefined:

    js> [[l1,typeof l2] for ([l1,l2] in {a:1, b:2})]
    a,undefined,b,undefined
    

    For reference – The standard for([] in {}) uses the following logic to determine the LHS validity:

    2775 #if JS_HAS_DESTRUCTURING
    2776                    ((JSVERSION_NUMBER(cx) == JSVERSION_1_7 &&
    2777                      pn->pn_op == JSOP_FORIN)
    2778                     ? (pn1->pn_type != TOK_RB || pn1->pn_count != 2)
    2779                     : (pn1->pn_type != TOK_RB && pn1->pn_type != TOK_RC)) &&
    2780 #endif
    

    Which seems to mean that versions other than 1.7 don’t require 2 left hand values for this syntax. The generator expression might be using older parsing logic. This might be worth submitting as a report to the SpiderMonkey maintainers.

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

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should use the bisect command to quickly figure out… May 15, 2026 at 3:06 pm
  • Editorial Team
    Editorial Team added an answer What Every Computer Scientist Should Know About Floating-Point Arithmetic goes… May 15, 2026 at 3:06 pm
  • Editorial Team
    Editorial Team added an answer You want to use input.getText().toString(), instead of (String) input.getText(); you… May 15, 2026 at 3:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.