A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Rest_with_default below:

SyntaxError: rest parameter may not have a default - JavaScript

SyntaxError: rest parameter may not have a default

The JavaScript exception "rest parameter may not have a default" occurs when a rest parameter has a default value. Because the rest parameter always creates an array, the default value would never apply.

Message
SyntaxError: Rest parameter may not have a default initializer (V8-based)
SyntaxError: rest parameter may not have a default (Firefox)
SyntaxError: Unexpected token '='. Expected a ')' or a ',' after a parameter declaration. (Safari)
Error type What went wrong?

A default parameter gives a parameter a default value if the argument is not passed or passed as undefined. A rest parameter collects all the remaining arguments passed to the function and always creates an array. Therefore, it doesn't make sense to have a default value for a rest parameter.

Examples Invalid cases
function doSomething(...args = []) {}
Valid cases
function doSomething(...args) {
  // args is always an array
}
See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4