Why arguments in all JavaScript Documentation are written like this? [duplicate]
JSON.stringify(value[, replacer[, space]])
All over MDN, the documentation represents arguments like this value[, replacer[, space]]
. What is the reason behind it?
What are the purpose of the square brackets?
Square brackets are used by a lot of programming environments, command line tools and documentation to show that arguments are optional.
The double brackets mean that supplying one of the optional arguments doesn't force you to provide a value for the others.
That means that replacer
is optional, and if you provide it, space
is optional again, and that you can't specify space
without specifying replacer
.
This opposed to: (sample)
JSON.stringify(value[, replacer, space])
Where you need to provide a value for space
if you provide a value for replacer
.
It's a convention. Simple as that. In this case square brackets denote optional arguments, meaning only the argument value
is really required.