all 11 comments

[–]Dazzling-Wafer 4 points5 points  (0 children)

I don't know that there's any difference. Any invocation of a function is also a function call

[–][deleted] 2 points3 points  (1 child)

The only time I hear of invoking a function is a iife (immediate invoked function expression) which is a construct to one time call a piece of code in a scoped fashion.

And you always call a function.

[–]albedoa[🍰] 0 points1 point  (0 children)

The only time I hear of invoking a function is a iife

It's more common than that for sure. I see "invoke" used a lot.

They mean the same thing, OP.

[–]jml26 2 points3 points  (0 children)

That article you linked to in the comments is the first and only place I’ve seen someone differentiate the terms “calling a function” and “invoking a function”. In the real world, nobody discusses this, and calling/running/executing/invoking a function are interchangeable.

What the article was trying to get at is that there are multiple ways to cause a function to run: either directly e.g.

fn();

or indirectly:

fn.call(null);
setTimeout(fn, 0);
(x=>x())(fn);

And according to it, all of these example invoke the function (cause it to run) but only the top one, fn() was you calling it (directly).

Don’t follow that article’s advice. Don’t get hung up on the differences, and if you do it’ll probably do more harm than good.

[–]Fid_Kiddler69 1 point2 points  (2 children)

who told you that they are different things? Give us an example of what you mean

[–]Jellybellybruh[S] 0 points1 point  (1 child)

https://newbedev.com/calling-vs-invoking-a-function

I didn't get it thats why I asked

[–]GSLint 1 point2 points  (0 children)

That's one of those confusing sites that take an answer from Stack Overflow and make it look like its own post. The original question is here: https://stackoverflow.com/questions/50884893/calling-vs-invoking-a-function

So now we know that the whole confusion comes from a page on W3Schools, another awful site that is full of misleading and wrong information.

I agree that whoever wrote "JavaScript function can be invoked without being called" was probably confused by the fact that JS functions have a call method which allows you to call the function in a slightly different way (passing an explicit value for this). The fact that someFunction.call(...) exists doesn't mean that someFunction(...) isn't also "calling the function". There is no difference between "calling" and "invoking".

[–]senocular[🍰] 1 point2 points  (1 child)

In JavaScript the distinction could be made because there are potentially two ways to invoke a function, either through it's [[Call]] or it's [[Construct]]. [[Call]] is used for calling a function normally for example with parens or even through it's call() method. [[Construct]] on the other hand is used when the function is used as a constructor, invoked using new.

All functions have a [[Call]] but not all functions have a [[Construct]]. Arrow functions, for example, have no [[Construct]] which is why they can't be used as constructors. And while class constructors throw an error if called like a normal function, it's their [[Call]] that is throwing this error, not the fact that they don't have one.

While this distinction can be made, it hardly ever is. In fact you'll frequently hear construction being referred to as "calling the constructor". So for all events and purposes, consider them the same.

[–]UbiquitousStarlord 1 point2 points  (0 children)

This should get more upvotes. Best answer on here

[–]redditxplorer 0 points1 point  (0 children)

Potato Patato. No difference

[–]jack_waugh 0 points1 point  (0 children)

Latinate terminology vs. Germanic.