DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. JavaScript call, apply, and bind Explained
XLinkedInReddit
Frontend Engineering

JavaScript call, apply, and bind Explained

D
DevPrep Team
February 10, 2026·2 min read·0
Table of Contents
  • The Problem
  • call() — Invoke with explicit this
  • apply() — Same as call, but array arguments
  • bind() — Returns a new function with fixed this
  • Comparison
  • Polyfill (Interview Classic)
  • Arrow Functions

These three methods control what this refers to inside a function. They're essential for understanding JavaScript's execution model.

The Problem

const user = {
  name: "Rahul",
  greet() {
    console.log(`Hello, I'm ${this.name}`);
  }
};

user.greet(); // "Hello, I'm Rahul" ✅

const greetFn = user.greet;
greetFn(); // "Hello, I'm undefined" ❌ (this lost!)

call() — Invoke with explicit this

function greet(greeting, punctuation) {
  console.log(`${greeting}, I'm ${this.name}${punctuation}`);
}

const rahul = { name: "Rahul" };
const priya = { name: "Priya" };

greet.call(rahul, "Hello", "!");  // "Hello, I'm Rahul!"
greet.call(priya, "Hi", ".");     // "Hi, I'm Priya."

// Arguments passed individually

apply() — Same as call, but array arguments

greet.apply(rahul, ["Hello", "!"]);  // "Hello, I'm Rahul!"

// Practical use: finding max in array
const numbers = [5, 2, 8, 1, 9];
Math.max.apply(null, numbers); // 9

// Modern alternative: spread operator
Math.max(...numbers); // 9

bind() — Returns a new function with fixed this

const greetRahul = greet.bind(rahul);
greetRahul("Hey", "!"); // "Hey, I'm Rahul!"

// Partial application
const helloRahul = greet.bind(rahul, "Hello");
helloRahul("!"); // "Hello, I'm Rahul!"

// Common in React (class components)
class App extends React.Component {
  constructor() {
    super();
    this.handleClick = this.handleClick.bind(this);
  }
}

Comparison

MethodInvokes immediately?ArgumentsReturns
callYesIndividualFunction result
applyYesArrayFunction result
bindNoIndividual (partial)New function

Polyfill (Interview Classic)

// Implement bind from scratch
Function.prototype.myBind = function(context, ...args) {
  const fn = this;
  return function(...newArgs) {
    return fn.apply(context, [...args, ...newArgs]);
  };
};

// Implement call
Function.prototype.myCall = function(context, ...args) {
  context = context || globalThis;
  const sym = Symbol();
  context[sym] = this;
  const result = context[sym](...args);
  delete context[sym];
  return result;
};

Arrow Functions

Arrow functions ignore call, apply, and bind. Their this is always lexical (from the enclosing scope).

const arrow = () => console.log(this);
arrow.call({ name: "Rahul" }); // Still window/global, not { name: "Rahul" }

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • The Problem
  • call() — Invoke with explicit this
  • apply() — Same as call, but array arguments
  • bind() — Returns a new function with fixed this
  • Comparison
  • Polyfill (Interview Classic)
  • Arrow Functions

Series

View all Frontend Engineering articles →

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.