1

I have come across this type of syntax in Node.js. Can anyone please explain what [, is in Node.js/JavaScript?

Examples of syntax I have seen.

  • assert(value[, message])
  • const name1 = value1 [, name2 = value2 [, ... [, nameN = valueN]]];
elixenide
  • 44,308
  • 16
  • 74
  • 100
bharadwaj
  • 492
  • 1
  • 4
  • 13

1 Answers1

6

You're looking at function definitions in documentation, and what you're seeing is a conventional way to show that one or more parameters are optional. It is not actually valid JavaScript syntax.

For example, assert(value[, message]) means that the value parameter is required, but message is optional. You could not actually put assert(value[, message]) in your code; it would trigger a syntax error.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • Thank you. I cannot find the same in google search because google ignores the special characters. So I asked here. – bharadwaj Mar 26 '16 at 16:41