js new function code example
Example 1: js function
var x = 10;
function créerFonction1() {
var x = 20;
return new Function("return x;");
}
function créerFonction2() {
var x = 20;
function f() {
return x;
}
return f;
}
var f1 = créerFonction1();
console.log(f1());
var f2 = créerFonction2();
console.log(f2());
Example 2: new function in javascript
var x=7;
function A(){
var x=70;
function B(){
console.log(x);
}
let C = function(){
console.log(x);
}
let D = new Function('console.log(x)');
B();
C();
D();
};
A();
Example 3: new function javascript
var add = function(num1, num2) {
return num1 + num2
}