Reading the mdn documentation on the difference between Function constructor and function declaration. The example specified there works on the browser and also on the node.js repl, but on trying it through a file, the node.js process crashed with this error
ReferenceError: x is not defined
This is the program
var x = "bar";
function test() {
var x = "baz";
return new Function("return x;");
}
var t = test();
console.log(t());
What might be the possible reason for this example not work as expected when been executed from a file with node.js?