Reputation: 23
While making a small thingy in javascript, I found that I could make comments /like these/
Because stack overflow's code doesn't color them, here's an image:
I haven't found anything about them, and I think they may have an extremely specific name and usage, because in no answer regarding comments I was able to find mentions of it.
For more specifity, I was using google's App Script, but because their documentation doesn't say anything about single slash comments, I doubt it is related to said IDE.
Also, I say it is a comment because when putting it in the middle of my code it acts like one, but the fact it's affected by the return shows it isn't really a comment, and leaves me even more clueless.
Any input or clue to continue searching would be greatly appreciated!
Edit:
Indeed it wasn't a comment, it is instead a weird unused expression, that JS understood as a comment in the specific situation it was in.
Also I'd like to point out the speed of the answerer; I refreshed the page to fix a typo and it was already answered in clear detail, thanks!
Edit 2:
Now knowing that it is an expression, I can see that a few of the things I found when looking for them, indeed mentioned them, for example this answer briefly noted that /[///]/
is an expression, but I confused the meaning of expression as "normal code" instead of the object meant for matching string patterns.
Upvotes: 0
Views: 798
Reputation: 370809
Single forward slashes delimit regular expressions, eg:
console.log(/abc/.test('fooabc'));
And unused expressions are permitted in JavaScript, though they're often confusing and shouldn't be used:
/abc/; // unused regular expression literal
The "comment style" you're seeing is a long regular expression literal, whose resulting expression isn't being used.
/why would you ever do this/;
/please don't/
console.log('program running');
I highly recommend against doing this in code anyone will have to maintain - it looks extremely strange. Maybe useful for something like a trivia question, but not for anything serious. Consider the ESLint rule no-unused-expressions.
Upvotes: 2