What is the difference between calling and invoking a function in JavaScript?

Up until now I though they were the same thing!

Hi there.

I’m sure one of the SU’s will correct me if I’m wrong, but there’s no difference - it’s two ways of referring to the same thing.

Consider I have the following function:

function sayHello(name) {
    console.log(`Hello there, ${name}!`);

If, later on, I write sayHello('vickyrai'); I can say either that I have called the sayHello() function or that I have invoked the sayHello() function.


Hi @thepitycoder! So after I posted I found the following on w3schools:

Invoking a JavaScript Function

The code inside a function is not executed when the function is defined .

The code inside a function is executed when the function is invoked .

It is common to use the term " call a function " instead of " invoke a function ".

It is also common to say “call upon a function”, “start a function”, or “execute a function”.

In this tutorial, we will use invoke , because a JavaScript function can be invoked without being called.

1 Like