3 ms·
I can think of a few when hoisting is nice, stylistically: if (...) var x = ... else x = ... ///// try { var x = ...} catch (error) { x = ... } ///// for
by nsonha 2y ago
I can think of a few when hoisting is nice, stylistically:
if (...) var x = ...
else x = ...
/////
try { var x = ...}
catch (error) { x = ... }
/////
for (...) {
var x: NodeJS.Dict<any> = {}
x[key] = ...
}
return x
- afavour 2y agoAll of those feel like anti patterns to me. Much more difficult to read.
- nsonha 2y agoThat's subjective, Idk about "MUCH more difficult". All it does is moving the declaration to the correct visual scope, instead of a dangling up-front declaration. Admittedly, I understand most coders are aready trained to read the latter.
- wruza 2y agoThe worst anti-pattern here is the catch- and finally-blocks living in a different scope. Really, who thought it was a good idea that finalization and error handling blocks must have no access to their subject scope? Every damn language copies that nonsense, except for js and its `var` hoisting.