News for hackers. Stuff that matters.
Re:HTML comments work in JavaScript too by chrismorgan on Tuesday March 08, 2022 @09:45AM (#30600432)
You kinda can:

  selector {
    //property: value;
  }
This sets the property named "//property" to "value". Close enough. (Expressed otherwise: it’s approximately a comment until the next semicolon, barring quoted strings and parentheses.)

  //selector {
    property: value;
  }
This is an invalid selector, and so the entire rule is ignored. (Expressed otherwise: it’s approximately a comment until the next opening curly brace’s matching closing curly brace.)
Re:HTML comments work in JavaScript too by zamadatix on Tuesday March 08, 2022 @10:02AM (#30600623)
Seems like it has plenty of disadvantages but no advantages to simply using the canonical method to do the same hack:

    /*
        // blah
    */
Edit: I mistakenly parsed this as using a dummy selector to hold the comment property, not just putting it inside real selectors.
Re:HTML comments work in JavaScript too by galaxyLogic on Tuesday March 08, 2022 @10:15AM (#30600772)
It is faster to type // than /* ... */ . Any time you type the same character twice it is much faster than typing two separate characters.

Further because I write a lot of JavaScript too I sometimes make the mistake of putting a // -comment into my CSS which breaks things. And when things break in CSS you usually don't get a clear error-message about it.

It is always difficult to switch between two languages. I would prefer something like JavaScript stylesheets, if that was possible.

Re:HTML comments work in JavaScript too by dylan604 on Tuesday March 08, 2022 @10:22AM (#30600844)
Unless you are commenting out multiple lines/blocks of code.
Re:HTML comments work in JavaScript too by galaxyLogic on Tuesday March 08, 2022 @04:29PM (#30607324)
True. But the IDE can of course help. In WebStorm I can select multiple lines of code and press Ctrl-/ to have them all turned into single-line comments if they were not, and uncomment them if they were.

Single-line comments have the benefit that it is always clear to the reader which lines are comments. Whereas if you use multi-line comments to comment a large section of code it is no longer clear when reading it whether it is indeed "inside" a comment.

And finally having both types of comments available is useful because you can multi-line-comment a section which already contains // -comments, whereas you can not multi-line comment a section which already contains multi-line comments.

Re:HTML comments work in JavaScript too by dylan604 on Tuesday March 08, 2022 @05:38PM (#30608269)
Commenting a comment is still a comment.

// => ////

//////////////////////////////////////////////////////////////

// just like those devs that like to decorate their code with

//////////////////////////////////////////////////////////////

/*

* type of stuff

*/

Edit: almost forgot my shell friends

########################

## works too

########################

Re:HTML comments work in JavaScript too by galaxyLogic on Tuesday March 08, 2022 @10:38PM (#30610643)
> Commenting a comment is still a comment

But what about the below, does it work in your language? I assume it may work in some languages but not all.

/*

let a = 1;

/* a is one */

let b = 2;

*/

Re:HTML comments work in JavaScript too by dylan604 on Wednesday March 09, 2022 @12:46AM (#30611306)
I can definitely see where that could cause some issues.

Personally, I don't like the /**/ style comments either. I was just playing devil's advocate.

Re:HTML comments work in JavaScript too by ptudan on Tuesday March 08, 2022 @10:25AM (#30600872)
This seems like the worst of both worlds. If you're going to use the /* */ I don't see why you'd bother with // unless it's about recognizing a comment in a single line.
Re:HTML comments work in JavaScript too by croddin on Tuesday March 08, 2022 @10:21AM (#30600832)
I have done the same type of thing to comment out lines of a json file used for configuration . Append “//“ or something to the beginning of a key that I want to have temporarily “commented out”. (Be careful as some programs might expect those keys not to be there of course.)
Re:HTML comments work in JavaScript too by hombre_fatal on Tuesday March 08, 2022 @05:34PM (#30608230)
Heh, I've done this in strict JSON config files:

    {
       "//": "lets us consume uncompiled protobufs (see issue #123)",
       "extern": "protobuf.js" 
    }