I have a function with a variable. I need to run code from a string to modify that variable. How would I set a local variable from new Function() or something similar?
function alertNumber() {
var number = 5;
var f = new Function("number = 4");
f();
console.log("local " + number); //should alert 4
console.log("window " + window.number); //instead of the local variable, it sets the property to the window
}
alertNumber();