-1

For example, this won't trigger any warnings from JSHint, even though one of the arguments isn't used by the function, and isn't even part of the function signature.

function foo(x) { return x; }

foo(4, 5);
wch
  • 4,069
  • 2
  • 28
  • 36

1 Answers1

1

No, it can't. The most likely reason for this is that a relatively common JavaScript pattern is to use the arguments collection to allow the passing of an arbitrary number of arguments. For example:

function findHighestNumber() {
  return Math.max.apply(Math, arguments);
}

findHighestNumber(1, 5, 19, 3); // 19

In this case, the function can accept any number of arguments and doesn't require any named parameters.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
  • Thanks. That's unfortunate though. I did a code refactoring that removed arguments from functions, and afterward I found that I had a number of calls to the function that still had the extra arg. JSHint warns about other common patterns -- such as unused arguments in a function, and this one seems no more common or objectionable than that. – wch Mar 16 '15 at 15:16