function Func() {
if (a === b) {
console.log("x");
} else {
console.log("y");
}
}
// replace with
function Func() {
if (a === b) {
Func = function() {
console.log("x");
}
} else {
Func = function() {
console.log("y");
}
}
return Func();
}
4: Detect non-null parameters
function IsRequired() {
throw new Error("param is required");
}
function Func(name = IsRequired()) {
console.log("I Love " + name);
}
Func(); // "param is required"
Func("You"); // "I Love You"
5: String creation function
const Func = new Function("name", "console.log(\"I Love \" + name)");