What is the correct JSDoc syntax for a local variable?

Kirkland picture Kirkland · Aug 1, 2016 · Viewed 12.8k times · Source

For a function like this...

function example() {
  var X = 100;

  ...

  var Y = 'abc';

  ...

  return Z;
}

I need to explain the purpose of some of the local variables. Adding a description like this...

function example() {
  /**
   * @description - Need to explain the purpose of X here.
   */
  var X = 100;

  ...

  /**
   * @description - Need to explain the purpose of Y here.
   */
  var Y = 'abc';

  ...

  return Z;
}

...doesn't seem to be getting picked up by JS Doc v3.4.0.

What is the correct syntax?

P.S. Some of my use cases call for multi-line comments.

Answer

mash picture mash · Aug 2, 2016

I usually use something like the code below in my projects.

function example() {
  /**
   * Need to explain the purpose of X here.
   * @type {number}
   */
  var X = 100;

  ...

  /**
   * Need to explain the purpose of Y here.
   * @type {string}
   */
  var Y = 'abc';

  ...

  return Z;
}