1

When going through docs or API's of JS libraries, I notice a "[," in params list.

Eg: vega.key(fields[, flat])

Does it mean optional arguments. How to interpret these.

2

2 Answers 2

2

It means optional argument. You will often see

someFunc(arg1[, arg2[, arg3]])

which means arg2 and arg3 are optional. When arg2 is passed to the function, arg3 need not be, because it's optional, but arg2 is necessary when arg3 is passed.

Sign up to request clarification or add additional context in comments.

Comments

1

It is a (widely-used) notation in documentation (and only in documentation; it is not valid syntax).

The part [, flat] means the second argument is named flat and it is optional.

The function can be called with two arguments (vega.key(fields, flat)) or with only one argument (vega.key(fields)). In this case, the comma must also be stripped (i.e. calling it as vega.key(fields,) is invalid syntax.

You will also encounter this notation: vega.key(fields[, flat, ...]) or vega.keys(fields[, ...]) that means the function can be invoked with one or more arguments; fields is required in the above notation, the others are optional.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.