Solved

ExpressionNoIn  in Javascript and other languages

Posted on 2013-05-19
10
445 Views
Last Modified: 2013-06-06
Hello,
What does the "NoIn" as in ExpressionNoIn mean.  I found it here;
http://tomcopeland.blogs.com/EcmaScript.html

Used in the Javascript For loop, opt is a subscript, which does not show it here;
for ( ExpressionNoIn opt ; Expression opt ; Expression opt )

As shown here; http://es5.github.io/  and in the ECMAScript 5.1

I know how the for loop work, no need to explain that   :)
0
Comment
Question by:chima
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 50 total points
ID: 39180059
It is not something that you can use in your code.  It has something to do with how the language code is designed.  The reference page is here: http://www.ecma-international.org/ecma-262/5.1/  I found some comments where others are as confused about it as you are but nothing about what it actually means.

Here's a page on BNF: http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39180330
I know how the for loop work
But do you also know this variant:
var a = ['a', 'b', 'c']; 
for (var i in a)
{
    alert(i + ': ' + a[i]);
}

Open in new window

On the link Dave posted, it is explained in 12.6.4 and ExpressionNoIn is defined at the very bottom of A.3

So I would say it is used to define that you cannot use the 'in' variant of an expression combined with the 'normal' variant of the for statement (using semicolons). Something quite logical probably but which they had to define in the language with a very elaborate rewrite doubling up a lot of the existing definitions...
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39180356
I had never seen that before.  Tried it, it worked.
0
 

Author Comment

by:chima
ID: 39182215
robert_schutt, I understand the code sample you posted, but I can't understand the
http://www.ecma-international.org/ecma-262/5.1/

And about section A.3 - Annex A (informative) Grammar Summary it is just more of the same :)

May I ask you a question about this section?
See >>> below, more than one.
12.6.4 The for-in Statement

The production IterationStatement : for ( LeftHandSideExpression in Expression ) Statement is evaluated as follows:

Let exprRef be the result of evaluating the Expression.
>>> The expession mentioned here is the "far right Expression" in the code/statement...right?

Let experValue be GetValue(exprRef).

If experValue is null or undefined, return (normal, empty, empty).
>>> Why are there three; "normal, empty, empt"  Isn't there only "null and undefined"?

Let obj be ToObject(experValue).

Let V = empty.
>>> What is "V" here? (this is the most important question).

Thank you, your code sample help;
My understanding is that you could not do this;
var a = ['a', 'b', 'c'];
for ( (var in a) ; Expression opt ; Expression opt )

Which does not make sense relative to the other expressions in the For loop.
0
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 150 total points
ID: 39182378
It's a fairly high level technical document. As Dave already remarked, more people are confused by it. To understand what it all means you have to start at page 1.

I usually get by with a working knowledge of these type of constructs, For me it's more important to know what the for statement does in general than to be able to explain the ECMA definition word for word, which I can't but will try to answer your questions at the end of this comment.

So for me it's most important to understand that with the 'var a' that I posted earlier this code:
for (var i in a)

Open in new window

is generally equivalent to:
for (var i = 0; i < a.length; i++)

Open in new window

Now, there are undoubtedly exceptions, that is why that formal definition is so complicated. In the context of that document it is not enough to say they are more or less the same, it has to be defined when they are the same or not. But for me it's often enough to know this is how it works and in this case specifically to know that ExpressionNoIn does indeed mean that it is a syntax error to use something like:
for (var i in a; i < a.length; i++)

Open in new window

but actually your common sense should already tell you that it would not be clear what this would do.

To get back on track, I think the answers to your questions are:
1) yes, in my example: a
2) not sure, describes an exceptional situation
3) Value assigned to be processed in the loop maybe, in my example each value assigned to i??
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:tliotta
ID: 39183657
One variant can use the "in" operator, and another variant must have no "in" operator. The first is expressed as simply {Expression}. The second is {ExpressionNoIn}. (I.e., {an Expression with no "in"}.)

That's really all it's trying to say.

Tom
0
 

Author Comment

by:chima
ID: 39184627
robert_schutt I greatly appreciate your comments and I do get your point.
Allow me to ask tliotta for one code example, if he wishes.

tliotta I think I know what you are saying, would think that the initial statement of;
for ( ExpressionNoIn opt ; Expression opt ; Expression opt )

would be (based on your comment; "The second is {ExpressionNoIn}. (I.e., {an Expression with no "in"}", would be shown as follows:
for ( ExpressionNoIn opt ; ExpressionNoIn opt ; ExpressionNoIn opt )

So, one code example would be greatly appreciated.
Thanks
0
 
LVL 27

Accepted Solution

by:
tliotta earned 300 total points
ID: 39186399
...would be shown as follows:
for ( ExpressionNoIn opt ; ExpressionNoIn opt ; ExpressionNoIn opt )


Well, except that isn't strictly correct. The second and third expressions don't have the same requirements as the first. The "in" operator isn't as much of a potential problem in those positions. The ExpressionNoIn expression is only meaningful in the first position.

Tom
0
 
LVL 27

Expert Comment

by:tliotta
ID: 39186407
I have to add a disclaimer that my comments are not "authoritative". They're purely from general experience and personal interpretation in case it helps spark useful insights. If I make sense and it helps, it might be coincidence.

Tom
0
 

Author Closing Comment

by:chima
ID: 39227517
I apologize for the delay on issuing the points.  Thank you all.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now