Mastering call, apply, and bind in JavaScript

🔹 Why call, apply, and bind exist In JavaScript, this keyword is not fixed. Its value depends on how a function is called, not where it’s written. call, apply, and bind let you manually control what this refers to. Here’s the simplest way to remember them 👇 call() • Invokes a function immediately • Passes arguments one by one fn.call(context, arg1, arg2) apply() • Invokes a function immediately • Passes arguments as an array fn.apply(context, [arg1, arg2]) bind() • Does NOT invoke immediately • Returns a new function with bound context const newFn = fn.bind(context) 👉 Key takeaway • call & apply → execute now • bind → execute later Understanding these helps you: • Control this • Write reusable functions • Debug tricky JavaScript issues Which one confused you the most when you started? #JavaScript #FrontendDevelopment #React #WebDev #JSFundamentals #LearningInPublic

To view or add a comment, sign in

Explore content categories