What Is the Difference Between Call, Apply, and Bind in JavaScript?

<p>JavaScript is a wonderful and wild language,&nbsp;full of hidden gems &nbsp;and quirky features that can make even seasoned developers raise an eyebrow.</p> <p>Today, we&rsquo;re going to examine some built-in functions of JavaScript&rsquo;s Function prototype with three essential methods:&nbsp;<code>call</code>,&nbsp;<code>apply</code>, and&nbsp;<code>bind</code>.</p> <p>These three musketeers are powerful tools when it comes to function invocation and changing the context of&nbsp;<code>this</code>&nbsp;inside a function. But when should you use each of them? Let&rsquo;s find out!&nbsp;</p> <h1>Picking Up the Pace with&nbsp;<code>call</code>&nbsp;</h1> <p>The&nbsp;<code>call</code>&nbsp;method is all about invoking a function with a specific&nbsp;<code>this</code>&nbsp;context and passing in arguments one by one.</p> <blockquote> <p>The&nbsp;<code>call()</code>&nbsp;method of&nbsp;<code>Function</code>&nbsp;instances calls this function with a given&nbsp;<code>this</code>&nbsp;value and arguments provided individually.<br /> &mdash;&nbsp;MDN Docs</p> </blockquote> <p>Think of it as a runner in a relay race , carrying the baton (the&nbsp;<code>this</code>&nbsp;value) and passing it on. Here&#39;s a quick example:</p> <pre> function introduce(firstName, lastName) { console.log(`Hello, my name is ${this.title} ${firstName} ${lastName}.`) } const person = { title: &quot;Dr.&quot; }; introduce.call(person, &quot;Derek&quot;, &quot;A&quot;) // &quot;Hello, my name is Dr. Derek A.&quot;</pre> <h1>Blasting Off with&nbsp;<code>apply</code>&nbsp;</h1> <p>Next up is the&nbsp;<code>apply</code>&nbsp;method, which, much like its sibling&nbsp;<code>call</code>, allows you to invoke a function with a specific&nbsp;<code>this</code>&nbsp;context.</p> <p><a href="https://medium.com/just-javascript-tutorials/what-is-the-difference-between-call-apply-and-bind-in-javascript-595b45333cc0">Website</a></p>