4 ms·
wild speculation: let/const is implemented by creating a new scope with every let or const declaration. Looking up variable then ends up tracing linearly throug
by winstonewert 6y ago
wild speculation: let/const is implemented by creating a new scope with every let or const declaration. Looking up variable then ends up tracing linearly through all of these scopes. Bundlers end up creating a huge number of let/const and thereby scopes. Then every variable reference ends up scanning through this huge linear list of scopes to find the variable it refers to.
- brundolf 6y agoWhy would there be a whole new scope for every declaration, instead of just each block? To prevent access within the block but before the declaration?
- nightcracker 6y agoProbably was simplest to implement, and then not looked at again.
- winstonewert 6y agoYes, I think creating a new scope for every let/const would be the simplest (but not very efficient) way to accomplishing that.