0

I noticed the @ symbols mentioned in many javascript files and couldn't figure out the significance of this character there. for example:

/**
    * Calls the specified callback function for all the elements in an array. The return value of
    * the callback function is the accumulated result, and is provided as an argument in the next
    * call to the callback function.
    * @param callbackfn A function that accepts up to four arguments. The reduce method calls the
    * callbackfn function one time for each element in the array.
    * @param initialValue If initialValue is specified, it is used as the initial value to start
    * the accumulation. The first call to the callbackfn function provides this value as an argument
    * instead of an array value.
*/

So, does the @param mean anything here?
P.S. - The above is a description of a function with callbackfn and initialValue as parameters.

  • that's for doc generation purpose - take a look for exapmple at http://usejsdoc.org/ – m.antkowicz Oct 20 '16 at 12:30
  • Possible duplicate: http://stackoverflow.com/questions/14143123/does-the-symbol-have-special-meaning-in-javascript-coffeescript-or-jquery – Tom Oct 20 '16 at 12:31

4 Answers4

3

That comment is JSDoc. The @param callbackfn means "what follows is the description of the argument callbackfn".

Your IDE might be able to parse that format or you can use jsdoc to generate documentation from that.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
1

It's only for documentation purpose.

@param is here to indicate which param your function will take for exemple. There is few more, like @author, etc.

Aks
  • 395
  • 3
  • 11
1

that is a javadoc style comment. look at the javadoc documentation

0

@param tag Specifies information for a parameter in a function or method.

link : https://learn.microsoft.com/en-us/visualstudio/ide/create-jsdoc-comments-for-javascript-intellisense?view=vs-2015