2

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

1 Answer 1

2

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()()

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, will that be the same way to go if the function was async?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.