Need help to understand the arguments syntax in functions at MDN web docs | Sololearn: Learn to code for FREE!
+ 4

Need help to understand the arguments syntax in functions at MDN web docs

what's with the weird array like notation in MDN for the arguments . syntax for Array.prototype.fill() is arr.fill(value[, start [, end]]), but I ll be using it like this , arr.fill( value, start, end) so what's the meaning of that nested array notation in arguments that I see everywhere, in MDN documentations https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill I understand all the functions but why that array notation in functions arguments

31st Jan 2018, 11:47 PM
Morpheus
Morpheus - avatar
5 ответов
+ 2
They are nested if an optional argument is only valid if it comes after another optional argument. In the example you provided, the start value is optional, and the end value is optional too. However, the end argument can only be used if the start argument has been used too, that's why the optional end argument is inside the optional start argument brackets.
1st Feb 2018, 12:05 AM
SplittyDev
SplittyDev - avatar
+ 5
Thank you splitty Dev, u know I was badly scratching my head because of that, 😅.
1st Feb 2018, 12:14 AM
Morpheus
Morpheus - avatar
+ 3
ok, but why nested then
1st Feb 2018, 12:01 AM
Morpheus
Morpheus - avatar
+ 2
Arguments in square brackets mean that they're optional.
1st Feb 2018, 12:00 AM
SplittyDev
SplittyDev - avatar
+ 2
No problem, I understand your confusion :P
1st Feb 2018, 12:20 AM
SplittyDev
SplittyDev - avatar