←back to thread

498 points azhenley | 1 comments | | HN request time: 0.216s | 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. stevage ◴[] No.45768564[source]
I'm talking about cases with additional logic that's too long for a ternary.