What is the difference between call() and apply() methods in JavaScript?

What is the difference between call() and apply() methods in JavaScript?

a) call() takes individual arguments, while apply() takes an array of arguments
b) call() is used for synchronous code, while apply() is used for asynchronous code
c) call() executes a function immediately, while apply() creates a promise
d) Both are identical

Answer:

a) call() takes individual arguments, while apply() takes an array of arguments

Explanation:

Both call() and apply() methods invoke a function with a given this context and arguments. The difference lies in how arguments are passed: call() takes individual arguments, while apply() expects an array of arguments.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top