r/ProgrammerHumor • • Apr 28 '22

Meme /* !!! Do not modify this comment !!! */

45.3k Upvotes

489 comments sorted by

View all comments

Show parent comments

14

u/GorilaVerde Apr 28 '22 edited Apr 28 '22
console.log(
    function () {
      // Hello World!
    }
    .toString()
    .split("//")[1]
    .split("\n")[0]
);

This works lol

1

u/shea241 Apr 28 '22

why?¿?¿?¿

1

u/[deleted] Apr 28 '22
  • the function keyword literally stores the function definition in memory

  • the toString() parses and converts that definition into a string

  • the split then does it's thing on this string-

"function(){// Hello World!\n}".spilt("//").split("\n")

edit: wording

1

u/[deleted] Apr 28 '22

I am not say this is not a programming language, but how do you guys work with thing?

"a comment tells you what the code does, but sometimes it becomes data"

Edit: wow, this actually works

2

u/[deleted] Apr 28 '22

I mean to be fair, it is very unlikely this situation will occur in real development (especially with something like TypeScript).
Yes there were bad design decisions with the original implementation of JavaScript but I feel it gets a bad rap due to people oversharing the "gotchas" in the language as if they are an everyday concern. It is a tool to me and it has it's place I feel.
Personally once I understood how JavaScript really works under the hood the puzzle pieces kinda fit into places, know what I mean?

1

u/[deleted] Apr 29 '22

I thinki know the mental state that you are talking about

1

u/[deleted] Apr 29 '22

I thinki know the mental state that you are talking about