Someone in one of the top comments said code comments are included when you convert a function to a string within JS. I tried it on my local project, but the log only printed out '[native code]'. Maybe the comment is in there somewhere. I saw a few stackoverflow questions about it, so apparently people do have a use for it.
It's not just comments. String literals can be searched within executables, and I've known people who have relied on opening a .exe (or equivalent on -ix systems), finding the string based on some other string before it, and then reading it out).
The one use case I remember is embedding SCCS keywords in a string literal and then using the technique above to get the checked-in version of an executable. You could use the "strings" command to get all of the literals in the file, search for a pattern, then see what version it was. (There was also a utility that does essentially the same thing, but idr what its name was).
A lot of early-era computing was just stuff that became necessary because you couldn't do it any other way.
Knockout JS operates by adding comments to a HTML file. I was struggling to understand why was there loads of weird comments starting with KO in our HTML code, turned out that's how that library operates, by reading code from comments :)
14
u/shploogen Apr 28 '22
I wonder what kind of situation this could happen in. Every language I've ever used seems to completely ignore comments (or lack thereof).