Different comments on Javascript

Asked

Viewed 254 times

1

I noticed that, at least in Notepad++, comments in the Javascript language are treated in two different ways, which are marked with two colors.

When I use // and "/* ... */ appears in green and when I use /// and "/* ... */ appears in blue, as shown below.

IDE com comentários destacados

Is there anything different between these kinds of comments? Some directives can be used just as we use in other languages to guide when compiling codes?

  • 2

    The '//' is only a comment, the '//' serves to summarize a method. When calling it, the summary will appear, along with the parameters and the return (if any). (Using C#. As I don’t know if this applies to Javascript, I just commented).

  • 2

    /// and /** are documentation comments. I couldn’t find out if there is a standardization in Ecmascript about this or is it a convention. The Jsdocs, PHP and other languages use this standard.

3 answers

4


The 3-Bar comment can be used to identify methods. For example, in Visual Studio 2017, when typing 3 bars, the IDE automatically creates a summary where I can identify your parameters, returns, etc...

/// <summary>
/// Faz algo com o metodo cliente
/// </summary>
/// <param name="Código"></param>
/// <param name="Nome"></param>
/// <param name="Desativado"></param>
public void Cliente(int Codigo, string Nome, bool Desativado)
{
  //Faz alguma coisa
}

The advantage of this is that I can "hide" the excess code and identify it just by reading its name.

inserir a descrição da imagem aqui

  • 1

    I think it would be interesting to highlight the "CAN" in the answer. The difference between comments is not intrinsic to the language; for Javascript all forms are mere comments. The difference is applied only in the editor. That is, the correct answer is "no difference to JS, but to the editor CAN make a difference".

3

No, there’s nothing in Javascript that makes the three-bar comment something different. Other languages use it like this, in JS at most you can consider it as different, but for language it is the same as doing this:

// /comentário aqui

There is nothing in the Ecmascript specification, and as far as I know no implementation considers this as special.

They said about C# and it’s true that it has special meaning in syntax, but in practice changes nothing to the code itself.

What should happen is the editor ends up using this rule from another language in JS to decide on the Highlight, which in a way is a flaw, on the other hand it may be useful to give this prominence to those who use this notation informally. Some documentation utilities use this pattern to indicate that it is a documentation and not code comment itself, so it turns out that it is useful for the editor to treat differently.

What I find curious is that Notepad++ treats this supposed documentation with the same color as the commentary with beginning and end, they have opposite semantics, so maybe it’s even an accident what happens with the three bars, something borrowed improperly from another language, sure just asking for the Notepad devs++.

-1

Basically:

"/* */" => For when you want to write more than one comment line

"//" => For one line comments

I’ve read about these comments that help when compiling only in c#...

I don’t know anything about this about Javascript.

a tip! download microsoft vs code! ahaha

  • Yes, these differences I use. However my doubt is when I use " " and " (2 bars or 3 bars) which are pointed with different colors. I wonder if there are some internal commands where we can use the three bars...

  • Hmmm understand, strange because I had never seen this kind of thing in javascript. Here in vs code, when using 3 bars it is in the same color as normal comment, which leads me to believe that they are considering the third bar as part of the comment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.