The Wayback Machine - https://web.archive.org/web/20240306101000/https://www.geeksforgeeks.org/javascript-function-call/
Open In App
Related Articles

JavaScript Function Call

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

A JavaScript function call is an action that invokes or executes a defined function to perform a specific task or computation. Functions in JavaScript are reusable blocks of code that can be defined with a name and a set of parameters. When you call a function, you are instructing the JavaScript interpreter to execute the code inside that function. In this article, we are going to learn JavaScript Function Call.

Syntax:

call()

Return Value:

It calls and returns a method with the owner object being the argument.

Example 1: Here is a basic example to describe the use of the call() method. 

Javascript

// function that returns product of two numbers
function product(a, b) {
    return a * b;
}
 
// Calling product() function
let result = product.call(this, 20, 5);
 
console.log(result);

                    

Output
100

Example 2: This example describes the use of function calls with arguments.

Javascript

let employee = {
    details: function (designation, experience) {
        return this.name
            + " "
            + this.id
            + designation
            + experience;
    }
}
 
// Objects declaration
let emp1 = {
    name: "A",
    id: "123",
}
let emp2 = {
    name: "B",
    id: "456",
}
let x = employee.details.call(emp2, " Manager ", "4 years");
console.log(x);

                    

Output
B 456 Manager 4 years

Example 3: This example describes binding a function to an object.

Javascript

let obj = { a: 12, b: 13 };
function sum() {
    return this.a + this.b;
}
console.log(sum.call(obj));

                    

Output
25

We have a complete list of Javascript Functions, to check those please go through the Javascript Function Complete reference article.

Supported Browser:

  • Google Chrome 1.0
  • Firefox 1.0
  • Microsoft Edge 12.0
  • Internet Explorer 5.5
  • Opera 4.0
  • Safari 1.0


Last Updated : 08 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials