Wednesday, September 15, 2021

In javascript how a function can return another function?

 In javascript function is object .So function can return another function .Example is below-

function interviewQuestion(job) {

    if (job === "engineer") {

        return function (name) { //annonymous function

            console.log(name + " can you please explain what is engineering");

        }

    } else if (job === "designer") {

        return function (name) {

            console.log(name + " how to design good UX");

        }

    } else {

        return function (name) {

            console.log(name + " don't be unemployed");

        }

    }

}

var question = interviewQuestion("engineer");// var question store the function expression .then                                                                                  called it.

question("lokman");

No comments:

Post a Comment

Element of a good table (Ref: Database design mere mortals by Michael J. Hernandez)

  Elements of the Ideal Table: It represents a single subject, which can be an object or event that reduces the risk of potential data integ...