❗lexical environment optimizaton
🚧 under construction
Last updated
Was this helpful?
🚧 under construction
Last updated
Was this helpful?
Was this helpful?
JS ⟩ concepts ⟩ scope ⟩ lexical environment ⟩ JS engine optimization
in theory while a function is alive, all outer variables are also retained.
but in practice, JS engines try to optimize that, if they find that an outer variable is not used – it is removed.
An important side effect in v8 (Chrome, Edge, Opera) is that such variable will become unavailable in debugging.
replit:lexical environment: optimization
let value = "Surprise!";
function f() {
// ⭐ `value` never used by `g`.
// ⭐ v8 will optimize it out from the "lexical environment"!
// ⭐ it's not accessable in the "debugger".
let value = "the closest value";