What is the difference between call(), apply(), and bind()?
Answer
All three methods control what this refers to inside a function. call(thisArg, arg1, arg2, ...): calls the function immediately with the specified this and arguments passed individually. greet.call(user, "Hello", "!"). apply(thisArg, [arg1, arg2, ...]): calls the function immediately with arguments passed as an array. greet.apply(user, ["Hello", "!"]). Useful when arguments are already in an array: Math.max.apply(null, numbers) (now use spread: Math.max(...numbers)). bind(thisArg, arg1, ...): does NOT call immediately — returns a NEW function with this permanently bound to thisArg and optional arguments pre-filled (partial application). const boundGreet = greet.bind(user). Common use: bind event handlers to preserve this: button.addEventListener("click", this.handler.bind(this)). Memory trick: call counts arguments, apply takes an array, bind binds for later.