Why are the arguments in all JavaScript documentation written as follows?

JSON.stringify(value[, replacer[, space]]) 

Throughout MDN, documentation includes arguments such as value[, replacer[, space]] . What is the reason for this?

What is the purpose of square brackets?

+5
source share
2 answers

Square brackets are used by many programming environments, command line tools, and documentation to indicate that arguments are optional.

Double brackets mean that providing one of the optional arguments does not force you to provide a value for the others.

This means that replacer is optional, and if you provide it, space is optional again, and that you cannot specify space without specifying replacer .

This contradicts: (sample)

 JSON.stringify(value[, replacer, space]) 

If you need to specify a value for space , if you specified a value for replacer .

+9
source

This is a convention. Just like that. In this case, the square brackets indicate optional arguments, which means that only the value argument is really needed.

+3
source

Source: https://habr.com/ru/post/1214054/


All Articles