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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:03:20+00:00 2026-05-25T14:03:20+00:00

These days I am reading some javascript source codes,however I found some syntax that

  • 0

These days I am reading some javascript source codes,however I found some syntax that I can not understand.

1)the for-in loop

var c;
var obj={name:'test',age:33};

for(var e in c={},obj){
    console.info(e+' = '+obj[e]);
}

2)The Conditional Operator (?:)

Generally,we use this operator this manner:

x > 0 ? x*y : -x*y

But I have seen some codes like this:

x > 0 ? (x*y,z=bar,..other expressoin) : (-x*y)

But it does not work if I change the comma to colon,it will throw a error.

  • 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-25T14:03:21+00:00Added an answer on May 25, 2026 at 2:03 pm

    In both cases, the comma operator [MDN] is used:

    You can use the comma operator when you want to include multiple expressions in a location that requires a single expression. The most common usage of this operator is to supply multiple parameters in a for loop.

    And the specification:

    11.14 Comma Operator ( , )

    Syntax

    Expression :
        AssignmentExpression
        Expression , AssignmentExpression
    

    (…)

    Semantics

    The production Expression : Expression , AssignmentExpression is evaluated as follows:

    1. Let lref be the result of evaluating Expression.
    2. Call GetValue(lref).
    3. Let rref be the result of evaluating AssignmentExpression.
    4. Return GetValue(rref).

    That just means that the result of the last expression is returned as result of the whole “list” of expressions.

    In the examples you gave, it is used for its side effects [Wikipedia], namely evaluating every expression.
    In general I’d say that this is not such a good style and, as you noticed, more difficult to understand.

    for(var e in c={},obj)
    

    is the same as

    c = {};
    for(var e in obj)
    

    an does not seem to add any value. Even better would have been to just initialize c in the first line: var c = {};.

    In case of the conditional operator: If x > 0 is true, then all the expressions are evaluated and the result of the last expression is returned. In this case, using a normal if statement would be better (easier to understand).

    Here again, the comma operator and maybe even the conditional operator seems to be used solely because of their side effects: Normally the conditional operator is supposed to only return a value but not to execute arbitrary expressions (a single function call which returns a value might be an exception).


    As the MDN documentation says, it is more commonly used in a for loop to initialize multiple variables:

    for(var i = 0, l = array.length; i < l; i++)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The general consensus these days seems to be that you do not store binary
Well, I am stuck again. Two days of reading and again, found some close
I was reading these days about large projects implementation in python and Flex, and
These days web addresses can also include non-ASCII characters. So every modern browser and
These days I'm working on a VB.NET application which can be used to edit,
Web-Applications these days make extensive use of Javascript, for example various Google Products like
I'm reading about visual programming languages these days. So I've thought up two paradigms.
I've spent whole days with PHP's DOM functions but i can't understand how it
in these days, i'm interested in software security. As i'm reading papers i see
I have been reading a lot about MVC these days and I think I

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.