Double-duty quine: quine!dlroW ,olleH
JavaScript (ES6), 42 38 bytes
f=_=>/\//g&&"f="+f||"!dlroW ,olleH">=_
Reversed
_=>"Hello, World!"||f+"=f"&&g//\/>=_=f
Explanation
When reversed, it becomes an anonymous function that returns the string Hello, World!
.
The regex /\//g
becomes a comment when it is reversed, which allows the syntactically invalid >=_=f
to be commented out in the reversed code.
Y, 19 bytes
Upxp"!dlroW ,olleH"
U
captures a string with U
at the beginning until the next U
is met, in this case, the source code. p
prints the item, and x
is a termination link. When reversed, this looks like:
"Hello, World!"pxpU
This captures the string and prints it with p
, again terminating the program with x
.
Try it here!
JavaScript (ES6), 71 bytes
trela=a=>alert("trela="+trela+"\ntrela\n``")//
`!dlroW ,olleH`
trela
``
How it Works:
Line 1 defines function trela
that when run outputs the program's source code. Line 2 is an unassigned string, does nothing. Lines 3 and 4 call trela
abusing the template string syntax.
Reversed:
``
alert
`Hello, World!`
//)"``n\alertn\"+alert+"=alert"(trela>=a=alert
How it Works:
Line 1 is an unassigned string, does nothing. Lines 2 and 3 abuse the template string syntax to print Hello, World!
. Line 4 is a comment.