Videos
Is the difference between them is just syntax or there's a performance issue?
Both, and more...
Rest parameters:
- Are a known idiom in other languages (Ruby, Python).
- Are easier to read and maintain (vs.
slice). - Are easier to understand for beginners.
- Can (and likely will) result in better performance, since engines can optimize.
- Are tool friendlier, as they can be analyzed statically.
In addition to @kangax’s response, I would elaborate that performance and correctness are problematic many times the arguments object is invoked. If you pass the arguments object to another function, you pass with it the right to modify the corresponding local variables in your scope.
function foo(arg) {
bar(arguments);
return arg;
}
function bar(args) {
args[0] = 20;
}
foo(10) // 20
The existence of this feature invalidates local reasoning within a function, which makes JIT optimization more difficult and introduces certain security hazards. Programs that are designed for speed must work around this problem with far more elaborate boilerplate code than the Array.prototype.slice.call(arguments) idiom, and in security contexts, the passing of arguments must be strictly disallowed.
Eliminating the need to use the arguments object to extract variadic arguments is one of the many advantages to the new syntax.