6

I'm still new to Javascript so when my editor highlights it I'm intrigued. what exactly does it do?

Example: /// things go after here

3
  • A more interesting thing to study is, what do three equals sign do? May 3, 2012 at 0:13
  • @MiaDiLorenzo: that's amazingly off-topic.
    – amelia
    May 3, 2012 at 0:44
  • @MiaDiLorenzo It compares two items by type and equality, IE (0 === false) will return false but (0 == false) won't. May 3, 2012 at 1:46

4 Answers 4

10

Some documentation generators regard three slashes /// as introducing documentation comments to JavaScript.

See

http://msdn.microsoft.com/en-us/library/bb514138(v=vs.110).aspx

So three slashes work the same as two slashes as far as JavaScript is concerned (it's a comment-to-end-of-line), but three slashes can be interpreted by documentation generators to indicate a documentation section.

Example:

  function getArea(radius)
  {
      /// <summary>Determines the area of a circle that has the specified radius parameter.</summary>
      /// <param name="radius" type="Number">The radius of the circle.</param>
      /// <returns type="Number">The area.</returns>
      var areaVal;
      areaVal = Math.PI * radius * radius;
      return areaVal;
  }
2

The first two slashes start a comment. The third slash does nothing.

The two main ways to comment in JS:

/* This way
Can go multi-line */

// This way is one line only
1

I believe it is a way to define a "higher level" single line comment in some editors/documentation programs:

E.g. In macrabbit's espresso editor it highlights these single line comments in the navigation pane

0

Three slashes in JavaScript (and some other languages such as C#) are used for documentation comments. These are used to generate XML documentation, and are done in a certain format before functions etc, to specify the description of the function and its parameters and parameter types.

http://msdn.microsoft.com/en-us/library/bb514138(v=vs.110).aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.