What is the difference between call() and apply() methods in JavaScript?
a)
call()
takes individual arguments, while apply()
takes an array of argumentsb)
call()
is used for synchronous code, while apply()
is used for asynchronous codec)
call()
executes a function immediately, while apply()
creates a promised) Both are identical
Answer:
a)
call()
takes individual arguments, while apply()
takes an array of argumentsExplanation:
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.