Function invocation operator question

I am trying to determine if I understand the function invocation operator properly. If I wanted to immediately run a function, when a page loads I would write the function with parentheses after the function name. This would signal to the function to run it immediately in the current scope.

If I don’t want to run the function immediately, but only after a certain action is done by the user (such as pressing a button), I would remove the parentheses which would tell the function to run only after something is done by the user.

If I want to run a function that has parameters that need to be specified, I would first put this function into an anonymous function, so that the desired function isn’t called immediately.

Is my understanding correct?

@kpav this sounds about right, yes.

Hello, kpav!

Your explanation is almost correct.
For example,

function num(x){
    console.log(x);
}

This has a parameter x which needs to be specified, but the function num isn’t called immediately and you don’t need to put this into an anonymous function. The function num is called by a button with the value.

Have a nice day!

I understand. Thank you for the explanation.