0

i've seen this syntax [, everywhere and have no idea what it implies.

 d3.mean(array[, accessor])

.on( events [, selector ] [, data ], handler )

Why is the comma after the opening bracket? What does it mean?

Eric Guan
  • 15,474
  • 8
  • 50
  • 61

2 Answers2

4

The comma is a separator between parameters. The square brackets mean that the parameter is optional.

So, when you read something like this:

.on( events [, selector ] [, data ], handler )

You can know that you have multiple options of how to call this function:

.on(events, handler)
.on(events, selector, handler)
.on(events, selector, data, handler)
Cole Cameron
  • 2,213
  • 1
  • 13
  • 12
1

It just means that the parameters are optional.

But be careful! These square brackets are just used in the documentation.

Tobias
  • 4,523
  • 2
  • 20
  • 40