V.Dimitrov V.Dimitrov - 1 month ago 10
Javascript Question

Can't reach returning function in JavaScript

I have problem with reaching the code of function that is returned by my 'main' function. Can anyone help me resolve this?



function createBook() {
let cnt = 1;


return function(selector,tiTle,auThor,rate){
alert("In");

}
}





When I debug the code the returning function is passed.

Answer

You need a call of the returned function to call the function inside.

function createBook() {
    let cnt = 1;
    return function (selector, tiTle, auThor, rate) {
        alert("In");
    }
}

// you need a call of the returned function to call the function inside
createBook()();