23

Often when reading documentation on what arguments can be passed to a method, I see brackets used within the arguments list like this:

example of brackets used within arguments on method documentation

What do the brackets mean in this context? Why are the commas inside the brackets?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Cooper Maruyama
  • 1,572
  • 13
  • 31

3 Answers3

42

required [optional] <required> [<optional>, <but both needed>].

This is almost always the case.

Zoey Mertes
  • 3,139
  • 19
  • 23
7

The brackets around a parameter means that it is optional.

When written separately like that, it means that you can use any of the parameters in any combination. The method determines what you use from the data type of the values. All these combinations can be used for that method:

.animate(properties, duration, easing, complete)
.animate(properties, duration, easing)
.animate(properties, duration, complete)
.animate(properties, duration)
.animate(properties, easing, complete)
.animate(properties, easing)
.animate(properties, complete)
.animate(properties)

You can see brackets used in other ways than around each parameters. For example:

.method(p1 [, p2 [, p3]])

This means that the second and third parameters are optional, and the third parameter can only be used if the second parameter is there.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

The square brackets mean they are optional parameters. You need not pass the optional parameters. .animate(properties) will work . Also the commas are inside the bracket because if it were outside, they would trail

animate(properties, [duration]) would mean properties and , are mandatory, whereas duration is not... It would like : animate(properties,)

SoWhat
  • 5,564
  • 2
  • 28
  • 59