0

I can understand apply function in Javascript. But I am unable to get how doesMath.max.apply(null,[arrayArg]) work.

The definition says apply calls the function for the giventhisvalue. Here, null is passed as the thisArg. Isn't the native Array constructor passed as the param as thisArg, as Array constructor doesn't has the function to find the maximum/minimum number from given argument?.

Prem
  • 5,685
  • 15
  • 52
  • 95
  • Can you give a working example? The snippet in your question looks like it'd just return `Number(arrayArg)`. But in general it would allow the maximum value from an array to be selected if it were populated correctly. – Patrick Roberts May 01 '18 at 03:58
  • How did `Array` get involved in `Math.max`? The point is that `Math.max` doesn't use `this` so it doesn't matter what you set it to – Raymond Chen May 01 '18 at 03:59
  • 4
    Possible duplicate of [How does the Math.max.apply() work?](https://stackoverflow.com/questions/21255138/how-does-the-math-max-apply-work) – xianshenglu May 01 '18 at 04:02

0 Answers0