Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this mean in documentation: square bracket followed by comma ( [, ) [duplicate]

Tags:

jquery

php

Today this caught my attention on jQuery's API Documentation for the closest selector:

.closest( selector [, context ] )

What exactly does [, context] mean? I know I can put a variable or jQuery object there to set as the context. This itself isn't entirely clear to me, but the part in particular I'm asking about today is the square bracket comma ( [, ). What does this mean? I've also seen similar notation on php.net's manual pages.

bool ob_start ([ callable $output_callback [, int $chunk_size = 0 [, ...

Is there some preliminary lesson I've missed? because this is greek to me and I can't be the only one who's looked at this and thought "WTF..." but ignored it and went on guessing, when I could have saved a lot of time...

like image 560
jamil Avatar asked May 24 '13 22:05

jamil


People also ask

What does square bracket mean in documentation?

Square brackets indicate optional parts of a statement. They should not be entered. In many cases, items in the square brackets are optional because default values are provided. | A vertical bar indicates a choice between two or more items or values, usually within square brackets or curly braces.

What do square brackets mean in a sentence?

Use square brackets to include words within a quote that are not part of the original quote. For example, if a quoted passage is not entirely clear, words enclosed in square brackets can be added to clarify the meaning.

Are square brackets parentheses?

Generally, 'parentheses' refers to round brackets ( ) and 'brackets' to square brackets [ ]. However, we are more and more used to hearing these referred to simply as 'round brackets' or 'square brackets'. Usually we use square brackets - [ ] - for special purposes such as in technical manuals.


2 Answers

It means that parameter is optional. You don't have to provide it and if you don't it will use the value you see listed there by default.

like image 183
John Conde Avatar answered Sep 22 '22 06:09

John Conde


Funnily enough, there's a dedicated page in the PHP manual on how to read a function definition. So, quoting the mentioned page:

All optional parameters are seen in [ brackets ].

Also, manual's "About the manual" is an interesting read, if you are into that.

like image 34
Diego Agulló Avatar answered Sep 20 '22 06:09

Diego Agulló