Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why arguments in all JavaScript Documentation are written like this? [duplicate]

Tags:

javascript

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?

like image 774
rahulroy9202 Avatar asked Feb 24 '15 09:02

rahulroy9202


2 Answers

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.

like image 195
Patrick Hofman Avatar answered Nov 13 '22 23:11

Patrick Hofman


It's a convention. Simple as that. In this case square brackets denote optional arguments, meaning only the argument value is really required.

like image 42
maryisdead Avatar answered Nov 14 '22 01:11

maryisdead