Axel Rauschmayer (2013-12-04T09:26:16.000Z)
On 04 Dec 2013, at 9:13 , Olov Lassus <olov.lassus at gmail.com> wrote:

> I wanted to do
> 
> if (const val = compute(something)) {
>     // ...
> }
> 
> but I had to do
> 
> let val;
> if (val = compute(something)) {
>     // ...
> }
>  
> which is unfortunate not only because val leaks to the outer scope but also because let suggest that the binding mutates (which it technically does, but practically doesn't).

I’m curious, why not:

```js
const val = compute(something);
if (val) {
    // ...
}
```

One thing that makes me skeptical w.r.t. `if`: will this kind of in-statement declaration only be used for truthy/falsy tests? In loops (for-of, while), I find this kind of thing useful, for if-then-else, much less so.

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131204/d573606a/attachment.html>
domenic at domenicdenicola.com (2013-12-10T01:43:49.672Z)
On 04 Dec 2013, at 9:13 , Olov Lassus <olov.lassus at gmail.com> wrote:

> I wanted to do
> 
> ```js
> if (const val = compute(something)) {
>     // ...
> }
> ```
> 
> but I had to do
> 
> ```js
> let val;
> if (val = compute(something)) {
>     // ...
> }
> ```
>  
> which is unfortunate not only because val leaks to the outer scope but also because let suggest that the binding mutates (which it technically does, but practically doesn't).

I’m curious, why not:

```js
const val = compute(something);
if (val) {
    // ...
}
```

One thing that makes me skeptical w.r.t. `if`: will this kind of in-statement declaration only be used for truthy/falsy tests? In loops (for-of, while), I find this kind of thing useful, for if-then-else, much less so.