Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the three slashes in javascript do?

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

like image 492
meticulousMisnomer Avatar asked Dec 21 '22 22:12

meticulousMisnomer


2 Answers

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;
  }
like image 62
Eric J. Avatar answered Jan 06 '23 16:01

Eric J.


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
like image 32
buley Avatar answered Jan 06 '23 15:01

buley