When you see something in brackets in programming, it typically denotes an optional argument. If you decide to use that optional argument, make sure to separate it with a comma from the previous argument.
For example:
arr.map(callback(currentValue[, index[, array]])[, thisArg])
can be written for clarity as:
arr.map(
callback(currentValue[, index[, array]])
[, thisArg]
)
This notation means that the callback function can take 1, 2, or 3 arguments. The .map
method requires the callback function as the first argument and optionally accepts a second argument (the thisArg
) as well.
Kaiido points out that in the case of Array.prototype.map
, even the currentValue
is considered optional. It's unusual but technically possible to use .map
without any arguments at all:
const arr = [3, 4];
const newArr = arr.map(() => 999);
console.log(newArr);