Tj1234
Tj1234

Reputation: 35

javascript onclick function does not run all code in function

This onClick function does not run the console.log in the code snippet below, any ideas?

var clickFunction = function myfunc() {
 return function (){
  return console.log('here');

  }
};

<button onClick="clickFunction()"> Click here</button>

Thanks for your time

Upvotes: 2

Views: 52

Answers (1)

aquinas
aquinas

Reputation: 23786

Because you're calling a function that returns a function. If you want to run the function that is returned you would need to do: clickFunction()()

Upvotes: 2

Related Questions