13

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...

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
jamil
  • 555
  • 5
  • 18
  • 2
    http://stackoverflow.com/questions/10925478/how-to-read-api-documentation-for-newbs/14362141#14362141 – Ry- May 24 '13 at 22:53
  • I looked for this question a lot, so sorry if I didn't find it. Do either have __ nevermind i see it in that question – jamil May 24 '13 at 22:54
  • @Jamil: No, the formatting is pretty standard — you just have to guess. (Well, apart from the occasional general documentation formatting advice, like in the linked question.) – Ry- May 24 '13 at 22:55
  • I have this exact question too! I wonder why they don't simply write [var] just as linux man page does. What's the point to put a comma in it? – mzoz Feb 09 '18 at 11:33
  • 1
    Thanks for the question! You saved my life! I was going to ask the exact same question about `[, arguments]` because I am sure I am not the only one who got confused about this and looking this syntax definition across the internet turns out to be difficult. – addicted Jul 26 '18 at 13:16

2 Answers2

6

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.

John Conde
  • 217,595
  • 99
  • 455
  • 496
3

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.

Diego Agulló
  • 9,298
  • 3
  • 27
  • 41