Monday, 4 Aug 2025
  • My Interests
  • My Saves
  • Try Intents
Subscribe
Focus - Code Reveals
  • Home
  • HTML

    What is the difference between “HTML” and “HTML5”?

    By Chief Editor

    What is Doctype HTML in HTML?

    By Chief Editor

    What is Block level Element and Inline Level Element?

    By Chief Editor

    Difference between HTML Tag and HTML Element in HTML?

    By Chief Editor

    What are the different types of HTML tags?

    By Chief Editor

    What are the async and defer attributes in the “script” tag?

    By Chief Editor
  • JavaScript

    What is Callback Hell in JavaScript?

    By Chief Editor

    What are the map, filter, and reduce methods in JavaScript?

    By Chief Editor

    What is Scope in JavaScript?

    By Chief Editor

    What is the this Keyword in JavaScript?

    By Chief Editor

    What is hoisting in JavaScript with an example?

    By Chief Editor

    What is the Event Loop in JavaScript?

    By Chief Editor
  • Frontend Interview

    What is Block level Element and Inline Level Element?

    By Chief Editor

    How to Reverse a String in JavaScript: Two Essential Methods

    By Chief Editor

    Is JavaScript a synchronous or asynchronous language?

    By Chief Editor

    Difference Between position: relative and position: absolute in CSS

    By Chief Editor

    What is Position in CSS?

    By Chief Editor

    Explain Deep Copy and Shallow Copy in JavaScript.

    By Chief Editor
  • Backend Interview

    How Does React Work?

    By Chief Editor

    What is a Promise in JavaScript, and what are its parameters?

    By Chief Editor

    What is Position in CSS?

    By Chief Editor

    What is Redux, and how does it work?

    By Chief Editor

    What is the Event Loop in JavaScript?

    By Chief Editor

    System Design and Frontend System Design: An In-depth Overview

    By Chief Editor
  • Nodejs
  • JavaScript Interview
  • React Interview
  • Frontend Interview
  • Backend Interview
  • Contact Us
  • Advertise with Us
  • Complaint
  • Cookies Policy
  • Privacy Policy
  • Donate
  • 🔥
  • ReactJS
  • JavaScript
  • JavaScript Interview
  • React Interview
  • HTML
  • Frontend Interview
  • CSS
  • Redux
  • Javascript
  • System Design
Font ResizerAa
Focus - Code RevealsFocus - Code Reveals
  • My Saves
  • My Interests
  • My Feed
  • History
  • Technology
Search
  • Homepage
  • ReactJS
  • JavaScript
  • JavaScript Interview
  • HTML
  • CSS
  • Backend Interview
Have an existing account? Sign In
Follow US
© 2022 Code Reveals Inc. All Rights Reserved.
Home Blog Explain Call, Apply and Bind in JavaScript.
JavaScript

Explain Call, Apply and Bind in JavaScript.

Chief Editor
Last updated: February 16, 2025 6:13 pm
Chief Editor
Share
SHARE

Call, Apply, and Bind in JavaScript

In JavaScript, call(), apply(), and bind() are methods that allow you to control the value of this when calling a function. They are especially useful when working with objects and borrowing methods.

Contents
1. call() Method2. apply() Method3. bind() MethodKey Differences Summary:When to Use Which?Practical Example Combining All:

1. call() Method

The call() method invokes a function immediately with a specific value for this, and you can pass arguments individually.

Syntax:

javascriptCopyEditfunctionName.call(thisArg, arg1, arg2, ...)

Example:

javascriptCopyEditconst person = {
    name: 'Alice',
    greet: function (city) {
        console.log(`Hello, my name is ${this.name} and I live in ${city}`);
    }
};

const person2 = { name: 'Bob' };

person.greet.call(person2, 'New York');
// Output: Hello, my name is Bob and I live in New York

Key Points:

  • call() calls the function immediately.
  • thisArg is the value of this inside the function.
  • Arguments are passed individually.

2. apply() Method

The apply() method is similar to call(), but it takes arguments as an array instead of individual values.

Syntax:

javascriptCopyEditfunctionName.apply(thisArg, [arg1, arg2, ...])

Example:

javascriptCopyEditconst person = {
    name: 'Alice',
    greet: function (city, country) {
        console.log(`Hello, my name is ${this.name} and I live in ${city}, ${country}`);
    }
};

const person2 = { name: 'Bob' };

person.greet.apply(person2, ['Los Angeles', 'USA']);
// Output: Hello, my name is Bob and I live in Los Angeles, USA

Key Points:

  • apply() calls the function immediately.
  • Arguments are passed as an array.
  • Useful when you don’t know the number of arguments in advance (e.g., Math.max.apply(null, [1, 2, 3])).

3. bind() Method

The bind() method returns a new function with a specific value for this, but does not call the function immediately.

Syntax:

javascriptCopyEditconst boundFunction = functionName.bind(thisArg, arg1, arg2, ...)

Example:

javascriptCopyEditconst person = {
    name: 'Alice',
    greet: function (city) {
        console.log(`Hello, my name is ${this.name} and I live in ${city}`);
    }
};

const person2 = { name: 'Bob' };

const boundGreet = person.greet.bind(person2, 'Chicago');
boundGreet(); // Output: Hello, my name is Bob and I live in Chicago

Key Points:

  • bind() does not call the function immediately.
  • Returns a new function with this permanently set to thisArg.
  • Useful when passing functions as callbacks or preserving this context in asynchronous operations.

Key Differences Summary:

MethodCalls the Function Immediately?Arguments Passed Individually or as an Array?Returns a New Function?
call()YesIndividuallyNo
apply()YesAs an arrayNo
bind()NoIndividuallyYes

When to Use Which?

Use CaseRecommended Method
Call a function immediately with a specific thiscall() or apply()
Pass arguments as an arrayapply()
Create a new function with this bound for later executionbind()
Event handlers, callbacks that need a fixed thisbind()

Practical Example Combining All:

javascriptCopyEditconst person = {
    name: 'Alice',
    age: 25
};

function introduce(city, country) {
    console.log(`Hi, I'm ${this.name}, ${this.age} years old, from ${city}, ${country}`);
}

// call
introduce.call(person, 'New York', 'USA');

// apply
introduce.apply(person, ['London', 'UK']);

// bind
const boundIntroduce = introduce.bind(person, 'Paris', 'France');
boundIntroduce();

Output:

rustCopyEditHi, I'm Alice, 25 years old, from New York, USA
Hi, I'm Alice, 25 years old, from London, UK
Hi, I'm Alice, 25 years old, from Paris, France
Share This Article
Email Copy Link Print
Previous Article Explain Deep Copy and Shallow Copy in JavaScript.
Next Article What is Flex Box in CSS?
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Trusted Source for Accurate and Timely Updates!

Our commitment to accuracy, impartiality, and delivering breaking news as it happens has earned us the trust of a vast audience. Stay ahead with real-time updates on the latest events, trends.
FacebookLike
XFollow
InstagramFollow
YoutubeSubscribe
LinkedInFollow
QuoraFollow
- Advertisement -
Ad imageAd image

Popular Posts

What is hoisting in JavaScript with an example?

Hoisting is a behavior in JavaScript where variables and function declarations are moved to the…

By Chief Editor

What is props drilling in React?

Props Drilling is a situation in React where data (props) needs to be passed through…

By Chief Editor

Mastering Star Rating Systems: Best Practices and Optimized Code Examples

Star rating systems are a common and effective way to collect user feedback on products,…

By Chief Editor

You Might Also Like

JavaScriptJavaScript Interview

What is the this Keyword in JavaScript?

By Chief Editor
JavaScript

What is the Event Loop in JavaScript?

By Chief Editor
JavaScriptJavaScript Interview

Difference between document.createElement and document.createElementFragement in JavaScript?

By Chief Editor
JavaScriptJavaScript Interview

What is Scope in JavaScript?

By Chief Editor

Focus by CodeReveals is your dedicated platform for mastering tech interviews and advancing your development skills. Whether you’re aiming to become a Frontend Developer, Backend Developer, or simply preparing for your next big interview, we’re here to guide you every step of the way.

Our mission is to help aspiring developers gain real-world knowledge, build confidence, and succeed in technical interviews. We offer structured content, curated interview questions, coding challenges, and practical guidance — all designed by experienced professionals who understand what top tech companies are looking for.

At Improve, we don’t just teach — we prepare you to think like a developer, solve like an engineer, and present like a pro.

Join us and start improving today — because your dream tech job is within reach

Most Famous
  • HTML
  • CSS
  • JavaScript
  • NodeJS
Top Categories
  • JavaScript Interview
  • React Interview
  • Frontend Interview
  • Backend Interview
Usefull Links
  • Contact Us
  • Advertise with Us
  • Complaint
  • Cookies Policy
  • Privacy Policy
  • Donate

©2025  Code Reveals Inc. All Rights Reserved.

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?