JS Built-ins
Functionapplybeginner

Function.prototype.apply() β€” basic usage

πŸ“– Usage Example
function add(a, b) { return a + b }
add.apply(null, [3, 4])  // β†’ 7

apply() invokes a function with a specified this and an array of arguments.

fn.apply(thisArg, argsArray)

apply() is like call() but takes arguments as an array instead of individually.

Challenge: Use add.apply(null, [2, 3]) and verify the result is 5.

πŸ’‘ Hints (1)
  • β€’ `apply()` takes an array as the second argument instead of spread args.