What does bracket mean in MDN javascript syntax document between each parameters?

前端 未结 1 402
情歌与酒
情歌与酒 2021-01-03 12:59

I do not understand what all these brackets mean in MDN javascript syntax document.

For example, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/G

1条回答
  •  孤街浪徒
    2021-01-03 13:21

    These brackets mean optional parameters. It means, you don't have to include those parameters.

    Example: Lets say I have function for incrementing: inc(x) Which needs one parameter. When called, it will increment that variable exactly by one. inc(x) equals x++ But I would like to have an option to increment by any number as well. Eg.: inx(x, 3) which gives the same result as x = x + 3. Then I can describe my function similarly as on MDN as:

    function inc(variable [,increment])
    

    0 讨论(0)
提交回复
热议问题