var b=new Function(“console.log(a);” );

  node.js, question

var server,a=1;
var b=new Function(“var c=require(‘express’); console.log(‘require’);” );
Why can’t this js run?
Node reported this error.
var c=require(‘express’); console.log(‘require’);
ReferenceError: require is not defined

var server,a=1;
var b=function(){var c=require(‘express’); console.log(‘require’); };
Can run under node.
Isn’t new Function the same as defining function?

The scope created by new function is in the global scope. The global scope does not have the require function, so that’s it.