15.
Which of the following is a function method that creates another function in JavaScript?
reverse()
slice()
pop()
bind()
Correct: D
The bind() method is a function method available in JavaScript. It allows you to create a new function with a specified this value and arguments. This can be useful for setting the context of a function or creating a partially applied function. The pop(), slice(), and reverse() methods are array methods, not function methods.
const person = {
firstName: "John",
lastName: "Doe",
};
function greet(message) {
console.log(`${message}, ${this.firstName} ${this.lastName}`);
}
const greetJohn = greet.bind(person);
greetJohn("Hello"); // Output: Hello, John Doe