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...
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With