Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JS 1.7: what is the "completion value of the let statement"?

11 views
Skip to first unread message

Nickolay Ponomarev

unread,
Sep 25, 2007, 10:34:43 AM9/25/07
to dev-tech-...@lists.mozilla.org
Hi,

A quick question about
http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7#let_statement

The article says "The completion value of the let statement is the
completion value of the block". I'm not sure what is this supposed to
mean. This would make some sense if |let| could be used in expression
context (like alert(let (a=1) { ... })), but it seems it can't be used
like that.

Sheppy says this sentence was copied from the es4 specification (proposal?).

I'm going to remove this sentence from the article, but wanted to
check if I'm missing something important first.

Nickolay

Blake Kaplan

unread,
Sep 25, 2007, 11:25:08 AM9/25/07
to
Nickolay Ponomarev wrote:
> The article says "The completion value of the let statement is the
> completion value of the block". I'm not sure what is this supposed to
> mean. This would make some sense if |let| could be used in expression
> context (like alert(let (a=1) { ... })), but it seems it can't be used
> like that.

Consider:

js> let (a = 1) { a }
1

In this case, in the JS shell, we have a let statement whose completion
value (the value of the statement) is the completion value of the block.

Also, I'm not sure what you mean "it can't be used like that" in your
example above. Your example shows a let expression -- you can't create a
let statement in the middle of another statement! Because of this, the
curly braces are parsed as an object initializer. You can also do:

js> print(let (a = 1) a)
1

which seems closer to what you want.
--
Blake Kaplan

Nickolay Ponomarev

unread,
Sep 25, 2007, 12:05:16 PM9/25/07
to dev-tech-...@lists.mozilla.org
On 9/25/07, Blake Kaplan <mrb...@gmail.com> wrote:
> Nickolay Ponomarev wrote:
> > The article says "The completion value of the let statement is the
> > completion value of the block". I'm not sure what is this supposed to
> > mean. This would make some sense if |let| could be used in expression
> > context (like alert(let (a=1) { ... })), but it seems it can't be used
> > like that.
>
> Consider:
>
> js> let (a = 1) { a }
> 1
>
> In this case, in the JS shell, we have a let statement whose completion
> value (the value of the statement) is the completion value of the block.
>
Thanks for the JS shell example. My confusion was caused by the fact
that I couldn't think of any cases where the completion value of a let
*statement* was visible.

eval() is another case when it's visible to a JS programmer.

> Also, I'm not sure what you mean "it can't be used like that" in your
> example above. Your example shows a let expression -- you can't create a
> let statement in the middle of another statement! Because of this, the
> curly braces are parsed as an object initializer. You can also do:
>
> js> print(let (a = 1) a)
> 1
>
> which seems closer to what you want.

Yeah, but the text about the completion value was in the "let
statement" section of the article (with a section on let expressions
below), so I tried to put a statement inside a statement to see the
completion value :)

I think I'm less confused now. Thanks again.

Nickolay

0 new messages