1

I came from a Java background and I'm studying Node.js & js in general.

I'm looking at this and this sample core functions from the Node.js library as I'm walking through a for-starters tutorial.

The documentation states what should be passed but I'm confused with the (foo[,bar]) part and I'm having a tough time understanding the following:

  • what does an argument enclosed in [] mean?
  • what's up with that comma inside (foo[,bar]) or ([foo][,bar])?
  • why is it that when I try to call createServer like this, it's not giving any errors stating to pass the arguments expected?
    const http = require("http");
    let server = http.createServer();
    
    console.log('running');
    server.listen(8080);
  • is there such a thing as optional arguments and how would I know if those are optional?

    Apologies for such a basic question but answers and advice are really appreciated.

  • iamkenos
    • 1,446
    • 8
    • 24
    • 49
    • 1
      `[]` means that this argument is optional. – t.niese Sep 27 '18 at 10:16
    • 2
      The syntax comes form unix manual pages (if you look up for the manual for ls or find for example the arguments will be using this syntax). The square brackets means that the argument is optional, you can give either one argument or two. The comma inside the square bracket because it would have been a syntax error if you give only one argument but end it with a comma – slebetman Sep 27 '18 at 10:16
    • 1
      Yeah, I guess saying "parameters in square brackets are optional" solves all of OP's questions. – VLAZ Sep 27 '18 at 10:17
    • see: https://stackoverflow.com/questions/8716047/is-there-a-specification-for-a-man-pages-synopsis-section – slebetman Sep 27 '18 at 10:18
    • 1
      Related: [What do the brackets around the arguments mean when reading documentation for a method?](https://stackoverflow.com/questions/21654192/what-do-the-brackets-around-the-arguments-mean-when-reading-documentation-for-a) – Ram Sep 27 '18 at 10:18

    0 Answers0