Why can't I figure out how to generate a "h" and a "C" in JavaScript without string literals or function calls?

It is possibly impossible.

Follow

If I could generate "h" and "C" from non-letter expressions, then I could remove the last three letters from this source code of an expression that evaluates to my name:

gist.github.com/Zatnosk/4d80a9

Unfortunately, I'm also missing "w" and "P", which would let me write "getOwnPropertyNames", which in turn would let me pull out "getCharCode" without touching "C" or "h".

Show thread

@zatnosk I love how obscure this is. How are you getting the other letters?

@noelle The primary technique is generating values and then converting them to a string that I then index into to get a letter.

"c" is generated with ([]+{})[!![]-[]+((!![]+!![])+[])]

([]+{}) results in string concatenation between an empty array and an object, which gives me "[object Object]".

Then that string is indexed into with "12" generated by !![]-[]+((!![]+!![])+[])

!![]-[] => true - "" => 1 - 0
!![]+!![] => true+true => 2
2 + [] => 2 + "" => "2"
1+"2" => "12"

@noelle with "m" it gets absurdly long, because I have to

1) make a number
2) generate the whole string "constructor" (which luckily doesn't contain an "m")
3) get the function Number() through 0.constructor aka 0["constructor"]
4) that becomes the string "function Number() {
[native code]
}" in Firefox, and similar enough in Chrome (only whitespace inside the function body differs)
5) and then index into that string with "11"
6) which is the letter "m"

@zatnosk what you are doing is a solved problem. All of JS can be written with six characters: []()!+

jsfuck.com/

cc @noelle

@makeworld @noelle you could have said that less condescendingly. -.-

Sign in to participate in the conversation
Manowar.social

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!