4 ms·
> The try-block would be way more useful if it could just define scope without being tied specifically to error handling. There are lots of circumstances where
by rictic 7y ago
> The try-block would be way more useful if it could just define scope without being tied specifically to error handling. There are lots of circumstances where defining scope would be handy outside of conditionals and creating functions for a similar purpose.
This is the case today! With `let` and `const`, any {} block creates a scope. So:
let foo = 'outside';
{
let foo = 'inside';
console.log(foo); // logs 'inside'
}
console.log(foo); // logs 'outside'