Andreas Rossberg (2013-12-04T09:26:27.000Z)
On 4 December 2013 10: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 don't understand. Why can't you do

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

instead? Or, if you also want to address the other half of your
concern, use an additional block (which admittedly is more verbose).

/Andreas
domenic at domenicdenicola.com (2013-12-10T01:44:13.334Z)
On 4 December 2013 10: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 don't understand. Why can't you do

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

instead? Or, if you also want to address the other half of your
concern, use an additional block (which admittedly is more verbose).