CS Fundamentals Trainer · JavaScript · Security
Predict the output: direct eval, indirect eval and new Function reading a variable.
Predict the output: direct eval, indirect eval and `new Function` reading a variable.
const x = 'module-local';
globalThis.x = 'global';
function run() {
const x = 'function-local';
console.log(eval('x'));
console.log((0, eval)('x'));
console.log(new Function('return x')());
}
run();
Difficulty: hard