2

I am trying to understand how to read javascript documentations. Why don't the square brackets close before the commas?

for example

d3.js: selection.style(name[, value[, priority]])

jQuery: $.load( url [, data ] [, complete ] )
2
  • 1
    Because they refer to non required parameters, and if there is no parameter name, no need for the comma either. Commented Jan 29, 2016 at 11:17
  • okay, i know this is probably a very silly question so bear with me. Are you saying that if the brackets close e.g. if the input arguments were ([name]), then it means 'name' is a required parameter/argument but if its (name[,value]) then 'value' is optional but 'name' is required? Commented Jan 29, 2016 at 11:22

1 Answer 1

5

Square brackets denote optional parts - just imagine drawing a strikethrough line from [ to the nearest ]. So in the jquery example you can omit data or complete or both:

$.load( url , data , complete ) - ok

$.load( url , data , complete ) - ok

$.load( url , data, complete ) - ok

In the d3 snippet, if you omit value, you also have to omit priority

selection.style(name , value, priority) - ok

selection.style(name, value , priority) - ok

selection.style(name , value , priority) - NOT ok

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

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.