⛔'xxx' is not defined❗️
JS ⟩ error ⟩ ReferenceError ⟩ 'xxx' is not defined
with a function in block (FiB)
sloppy mode: ✅ hoisted / initialized to undefined (in outer scope)
strict mode: ⛔ ReferenceError (invisible in outer scope)❗
replit:modify scope at runtime
function evalCantModifyScopeInStrictMode() {
'use strict'; // ⭐️ strict mode
// ---------------------------------------------------------------
// ⭐️ in strict mode, `eval` doesn't introduce new variables into
// the surrounding scope, they're local to the script itself.
eval("var b = 'bbb!';");
// ╰── `b` is "local" to the inner script❗
// ---------------------------------------------------------------
console.log(b); // `b` is invisible.
// ^
// ⛔ ReferenceError: `b` is not defined
}
evalCantModifyScopeInStrictMode(); // ⛔ ReferenceError (runtime error)Last updated
Was this helpful?