It means that whatever is in the brackets is an optional argument. If you do use an additional optional argument, you need a comma to separate it from the previous argument.
The notation
arr.map(callback(currentValue[, index[, array]])[, thisArg])
perhaps more easily read as
arr.map(
callback(currentValue[, index[, array]])
[, thisArg]
)
means that the callback can accept 1, 2, or 3 arguments, and that .map
accepts the callback as the first argument, and can optionally accept a second argument (the thisArg
) as well.
As Kaiido notes, in the specific case of Array.prototype.map
, the currentValue
is actually optional as well, it's just extremely odd to use .map
without using any of the arguments:
const arr = [3, 4];
const newArr = arr.map(() => 999);
console.log(newArr);