Closed frobinsonj closed 5 years ago
Hmm. That is strange. .0000001
would be 1e-7
and .00000001
is 1e-8
.
It’s because you unwrapped the number from +[]
.
The expressions inside the definitions are not real JavaScript expressions
@hazzik, if that is the case, why does it work with 7 zeros and not 6? (((.00000001)+"")[2]
and not ((.0000001)+"")[2]
)
Another option would be to just use (+((+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+!+[]])+[])[!+[]+!+[]]
which saves a further 3 characters (18 in total)
if that is the case, why does it work with 7 zeros and not 6? (((.00000001)+"")[2] and not ((.0000001)+"")[2])
Because if there are 6 zeros the number gets converted to 0.000001
, eg it loses one 0
(because somewhere the string concatenation is replaced with a sum). With 6 zeros the number becomes "1e-7"
(instead of "1e-8"
).
So, this works: '(+(.+[0000001])+"")[2]'
and saves 3 characters.
So, this is this: (+(.0000001)+"")[2]
(+((+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+!+[]])+[])[!+[]+!+[]]
_________________________________________________________the error is HERE ^^^^
And this is (+(.0000001)+"")[2]
(+((+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+!+[]])+[])[!+[]+!+[]]
___________________________________________________________same error HERE ^^^^
And this is correct version: (+(.+[0000001])+"")[2]
(+((+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]+[+[]+[+[]]+[+[]]+[+[]]+[+[]]+[+[]]+[+!+[]]])+[])[!+[]+!+[]]
______________________________________________________________no error HERE ^^^^
The error happens because of the number replacer here: https://github.com/aemkei/jsfuck/blob/977aeeff2a924a1747baf0ee34738f435fdcec05/jsfuck.js#L184
Thanks for the explanation @hazzik :)
I will update the branch.
@aemkei, I've updated the branch. Thanks again hazzik.
Perfect. Guess we once need to add an explanation to the README about how the character mapping works.
Managed to save 15 characters here.
I am a bit confused why
((.0000001)+"")[2]
doesn't work here. It returns"-"
in all browsers and node.js but returns0
in tests. Any idea why?