←back to thread

498 points azhenley | 1 comments | | HN request time: 0.209s | source
Show context
stevage ◴[] No.45768231[source]
In JavaScript, I really like const and have adopted this approach. There are some annoying situations where it doesn't work though, to do with scoping. Particularly:

- if (x) { const y = true } else { const y = false } // y doesn't exist after the block - try { const x = foo } catch (e) { } // x doesn't exist after the try block

replies(4): >>45768310 #>>45768515 #>>45768529 #>>45771225 #
askmrsinh ◴[] No.45768515[source]
Why not do:

const y = x ? true : false;

replies(2): >>45768564 #>>45773065 #
1. 1718627440 ◴[] No.45773065[source]
That sounds like a more complicated way to write

    const y = (bool)x;
or

    const bool y = x;