🌐
W3Schools
w3schools.com › js › js_function_call.asp
JavaScript Function call() Method
What is the main difference between call() and a normal function call? ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Function › call
Function.prototype.call() - JavaScript - MDN Web Docs
call() is almost equivalent to a normal function call, except that this is passed as a normal parameter instead of as the value that the function was accessed on.
Discussions

Need help understanding function calls in JavaScript
Congratulations! You are wading into "higher-order functions" (i.e. functions that call other functions). This is a powerful technique which underpins a lot of super useful JavaScript methods, but is often confusing at first. Best thing you can do is open up your console (or wherever you prefer to run JavaScript code), and mess around until it starts to click. Let's look at some examples you can start with. Let's clear up your question first. No, functions are not called when you declare them. Like in PHP and other languages, declaring a function is essentially just stashing a code snippet away for later. Nothing at all will happen with that code until the function is called. We can experiment with this ourselves by defining the JS equivalent of that PHP function you posted and not calling it. function helloWorld() { console.log("Hello world!"); } . . . Nothing logged! Similarly, nothing will log if we define the equivalent function with the arrow syntax but do not call it. const helloArrow = () => console.log("Hello arrow!"); Don't take my word for it! I encourage you to open your console and copy and paste this code in. See for yourself that nothing happens. And make any modifications you want if you are curious about some edge case or something. Okay, now just to make sure we're not crazy, let's call these functions. helloWorld(); // Hello world! helloArrow(); // Hello arrow! helloWorld(); // Hello world! helloWorld(); // Hello world! All appears to be in order. Let's actually move on to higher-order functions. So, your confusion around map stems from the function getting invoked "without anyone calling it". But in fact, someone did call your arrow function. You did. Think of it like a Rube Goldberg machine. You called map and passed it your function. Then map calls your function. Multiple times in fact. Once per item in the array. Let's try the same thing with another higher order function, forEach . What will happen if we pass it our helloWord function? const nums = [1, 2, 3]; nums.forEach(helloWorld); // ??? Make your own hypothesis, then copy that code into your console, run it and find out. See if your hypothesis matches reality. If not, what were you missing? Answer below: "Hello world!" gets logged to the console three times. Okay. So let's bring it back to map. I think the best thing we can do is build our own version, so you can see the mechanics of the Rube Goldberg machine for yourself. I'm going to build a slightly simplified version of JS's map using a for...of loop . const myMap = (arr, fn) => { const mapped = []; for (const item of arr) { mapped.push(fn(item)); } return mapped; }; Since this is a function not a method, we will call it a little differently than JS's version, the array will go in between the parentheses instead of to the left of the dot. But the result will be the same. const doubled = myMap(nums, x => x * 2); console.log(doubled); // [2, 4, 6]; So who is calling the function we passed into myMap? Well, myMap is. Now that we've written our own version, you can see it happen above, right in the middle of the for loop. The point of map and other higher-order functions is to handle the mechanics of a generic operation you need to do often, like mapping over the data of one array in order to transform it into a new array. You get to skip all that boilerplate. Just define your particular business logic (like doubling a number), and pass it in as a function. Once again, I can't emphasize enough how useful it is to copy and paste this code into your console so you can play around with it yourself. Do that for awhile, and if you have any more questions, feel free to ask. More on reddit.com
🌐 r/learnjavascript
9
5
November 16, 2020
javascript - Calling vs invoking a function - Stack Overflow
So you might consider instantiation ... could also be considered an invocation rather than a call. But W3Schools' insistence on using "invoke" everywhere seems very unnatural to me. ... "because a JavaScript function can be invoked without being called"...... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Defining and calling function in one step - Stack Overflow
Is there a way in Javascript to define a function and immediately call it, in a way that allows it to be reused? I know you can do one-off anonymous functions: (function(i) { var product = i... More on stackoverflow.com
🌐 stackoverflow.com
Calling functions within another function
This is fine. They are called nested functions. As long as you keep things organized and it's not becoming spaghetti code, there is no problem. Just remember that variables you create witin a function will stay local. And actually, this is a good way to save time. Any kind of operation you need repeated regularly, you should create a function for it; reduces amount of code. More on reddit.com
🌐 r/learnjavascript
2
2
June 8, 2022
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Functions
Functions - JavaScript - MDN Web Docs
A function in JavaScript is similar ... obvious relationship between the input and the output. To use a function, you must define it somewhere in the scope from which you wish to call it....
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-function-call
JavaScript Function Call - GeeksforGeeks
July 11, 2025 - It can be used to invoke (call) a method with an owner object as an argument (parameter). This allows borrowing methods from other objects, executing them within a different context, overriding the default value, and passing arguments.
🌐
W3Schools
w3schools.com › js › js_function_invocation.asp
JavaScript Function Invocation
To call a function, write the name followed by parentheses like name(). The code inside a function is NOT executed when the function is defined.
🌐
Reddit
reddit.com › r/learnjavascript › need help understanding function calls in javascript
r/learnjavascript on Reddit: Need help understanding function calls in JavaScript
November 16, 2020 -

I am not sure but from what I understand JS functions can be invoked without anyone calling them, they call themselves?

Example from the built-in 'map()' method:

const array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]

the x = > x * 2 is an arrow function. The map iterates it. But I am used to calling functions from other languages. For example PHP when you declare a function first:

function helloWorld() {
echo "Hello world!";
} 
helloWorld();

But in JS functions are called when declared?

Top answer
1 of 4
7
Congratulations! You are wading into "higher-order functions" (i.e. functions that call other functions). This is a powerful technique which underpins a lot of super useful JavaScript methods, but is often confusing at first. Best thing you can do is open up your console (or wherever you prefer to run JavaScript code), and mess around until it starts to click. Let's look at some examples you can start with. Let's clear up your question first. No, functions are not called when you declare them. Like in PHP and other languages, declaring a function is essentially just stashing a code snippet away for later. Nothing at all will happen with that code until the function is called. We can experiment with this ourselves by defining the JS equivalent of that PHP function you posted and not calling it. function helloWorld() { console.log("Hello world!"); } . . . Nothing logged! Similarly, nothing will log if we define the equivalent function with the arrow syntax but do not call it. const helloArrow = () => console.log("Hello arrow!"); Don't take my word for it! I encourage you to open your console and copy and paste this code in. See for yourself that nothing happens. And make any modifications you want if you are curious about some edge case or something. Okay, now just to make sure we're not crazy, let's call these functions. helloWorld(); // Hello world! helloArrow(); // Hello arrow! helloWorld(); // Hello world! helloWorld(); // Hello world! All appears to be in order. Let's actually move on to higher-order functions. So, your confusion around map stems from the function getting invoked "without anyone calling it". But in fact, someone did call your arrow function. You did. Think of it like a Rube Goldberg machine. You called map and passed it your function. Then map calls your function. Multiple times in fact. Once per item in the array. Let's try the same thing with another higher order function, forEach . What will happen if we pass it our helloWord function? const nums = [1, 2, 3]; nums.forEach(helloWorld); // ??? Make your own hypothesis, then copy that code into your console, run it and find out. See if your hypothesis matches reality. If not, what were you missing? Answer below: "Hello world!" gets logged to the console three times. Okay. So let's bring it back to map. I think the best thing we can do is build our own version, so you can see the mechanics of the Rube Goldberg machine for yourself. I'm going to build a slightly simplified version of JS's map using a for...of loop . const myMap = (arr, fn) => { const mapped = []; for (const item of arr) { mapped.push(fn(item)); } return mapped; }; Since this is a function not a method, we will call it a little differently than JS's version, the array will go in between the parentheses instead of to the left of the dot. But the result will be the same. const doubled = myMap(nums, x => x * 2); console.log(doubled); // [2, 4, 6]; So who is calling the function we passed into myMap? Well, myMap is. Now that we've written our own version, you can see it happen above, right in the middle of the for loop. The point of map and other higher-order functions is to handle the mechanics of a generic operation you need to do often, like mapping over the data of one array in order to transform it into a new array. You get to skip all that boilerplate. Just define your particular business logic (like doubling a number), and pass it in as a function. Once again, I can't emphasize enough how useful it is to copy and paste this code into your console so you can play around with it yourself. Do that for awhile, and if you have any more questions, feel free to ask.
2 of 4
3
What's happening here is that your arrow function (x => x * 2) is being used as a callback function by map. So when you are defining array1.map(do stuff), map is immediately executing the do stuff piece. You can read the documentation for map here , with special importance given to the "polyfill" portion, since this is the actual code for the map function. Basically executing array.map() is like saying "map function, execute your callback", which in this case is your arrow function. Arrow functions aren't working any differently than any named javascript function in terms of execution. As an example, try out this code: const hi = () => console.log('there'); You'll see that it doesn't print out "there" like we would expect. This is because the arrow function still needs to be invoked with hi(). Hope this helps!
🌐
Programiz
programiz.com › javascript › library › function › call
Javascript Function call() (With Examples)
The JavaScript Function call() method calls a function with a given this value and arguments provided individually. The call() method calls a function by passing this and specified values as arguments.
🌐
Mimo
mimo.org › glossary › javascript › calling-the-function
Calling functions in JavaScript: Execute code effectively
In JavaScript, calling a function means executing the code inside the function body.
Find elsewhere
🌐
Talent500
talent500.com › blog › demystified-the-call-method-in-javascript
Demystified the call() method in JavaScript
November 27, 2023 - The call() method in JavaScript allows us to invoke a function with a specified value for this keyword and arguments provided individually. It is useful for explicitly setting the context for a function or passing arguments one by one.
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_function_call.htm
JavaScript - Function call() Method
The Function call() method allows us to invoke a function given a specific value for this and arguments provided individually. When a normal function is called, the value of this inside the function is the object that the function was accessed on.
🌐
Scaler
scaler.com › home › topics › how to call a function in javascript?
How to Call a Function in JavaScript - Scaler Topics
July 13, 2023 - Using Parenthesis: The most common way to call a function is by using parentheses after its name, passing any required arguments inside the parentheses. Using the call() function: The call() function is a method available on all JavaScript functions.
🌐
Chris Pietschmann
pietschsoft.com › post › 2019 › 07 › 24 › call-functions-in-javascript
Call Functions in JavaScript | Chris Pietschmann
July 24, 2019 - If you have a JavaScript object ... the call() method. The call() method enables you to call a function by passing in the context for the this keyword within the function, and any required parameters....
🌐
SheCodes
shecodes.io › athena › 2139-calling-functions-in-javascript
[JavaScript] - Calling Functions in JavaScript - SheCodes | SheCodes
Learn how to call a function in JavaScript with parameters and parentheses, including an example and code snippet.
🌐
Hyno
hyno.co › blog › javascript-function-call-a-comprehensive-guide-with-examples.html
JavaScript Function Call: A Comprehensive Guide with Examples
Consider performance implications when calling functions within loops or frequently executed code blocks. In this comprehensive guide, we explored JavaScript function calls, covering various aspects such as syntax, arguments, types of function calls, context, the this keyword, function call stack, passing functions as arguments, debugging, and best practices.
🌐
Codecademy
codecademy.com › forum_questions › 557ac8d276b8fe52170005b7
What is function call? | Codecademy
You call the function by typing its name and putting a value in parentheses.
Top answer
1 of 5
50

Your reference text:

It is common to use the term "call a function" instead of "invoke a function" ... In this tutorial, we will use invoke, because a JavaScript function can be invoked without being called.

Now let me rephrase it:

It is common to use the term "call a function" instead of "invoke a function" ... In this tutorial, we will use the term invoke instead of call, because a JavaScript function can be invoked indirectly like fn.call() and fn.apply() without being called directly like fn().

So, when I do fn(), it's invoked directly and when I do it like fn.call(), it's invoked indirectly but in both cases, the function is being invoked. Otherwise, I see no difference here and I can also say that I can call a function in many ways, for example:

fn(); // I'm calling it
fn.call(); // I'm calling it
fn.apply(); // I'm calling it

So, the difference is semantic but both are interchangeable, IMO. BTW, I wrote a comment above, under the question and I would like to put it here, which is:

IMO, that's a misleading statement. Maybe there are some indication of call/apply or something else but it's totally confusing.

2 of 5
32

The difference is semantic and subtle. When you call a function, you are directly telling it to run. When you invoke a function, you are letting something run it.

There is one way to call a function:

myFunction()

Here, you are invoking the function (letting it run) by calling it directly.

There are many ways to invoke a function (given throughout different comments and answers). Here's one example:

function invoker(functionName) {
  functionName() 
}

invoker(myFunction)

Here, by calling invoker, you are invoking myFunction, which is being called indirectly.

🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript call() method
JavaScript call() Method and Its Practical Applications
October 6, 2023 - The call() method returns the result of calling the functionName(). The following example defines the add() function and calls it normally: function add(x, y) { return x + y; } let result = add(10, 20); console.log(result); // 30Code language: ...
🌐
Delicious-insights
delicious-insights.com › en › posts › call-and-apply-in-javascript
Call a JavaScript function with an explicit this • Delicious Insights
February 25, 2020 - Complement: we immediately call the obtained function, on-the-fly within the expression term (using the () operator, surrounding any arguments). ... Everything’s dandy. If we take that expression apart, we do find: ... In that case and that case only, JavaScript will define (among other things) this in the context of that call (technically, it adds 4 extra entries to the call’s Function Environment Record), using the subject as reference.
🌐
Medium
noncodersuccess.medium.com › the-magic-of-call-in-javascript-the-key-to-dynamic-function-execution-in-javascript-unleash-d0230c2039f6
The Magic of call() in JavaScript | The Key to Dynamic Function Execution in JavaScript | Unleash the Power of Function Invocation | by NonCoderSuccess | Medium
August 11, 2024 - In JavaScript, the this keyword refers to an object. The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object. Alone, this refers to the global object. In a function, this refers to the global object. In a function, in strict mode, this is undefined. In an event, this refers to the element that received the event. Methods like call(), apply(), and bind() can refer this to any object.