JSFuck is an esoteric and educational programming style based on the atomic parts of JavaScript. It uses only six different characters to write and execute code.
It does not depend on a browser, so you can even run it on Node.js.
Let's start with the opening and closing brackets and see what is possible here. They are super useful for this project and are considered as a core element because they provide a way to:
deal with arrays
access properties and methods.
[] – Array Literals
Create new arrays:
[]// an empty array[[]]// an array with one element (another array)
[X][i] – Array / Object Access
[][[]]// undefined, same as [][""]
Later we will be able to do this:
"abc"[0]// get single letter[]["length"]// get property[]["fill"]// get methods
[X][0] - Array wrapping trick
By wrapping an expression in an array and then getting the element at index zero, we can apply several operators on one expression. This means brackets [] can replace parenthesis () to isolate expressions:
[X][0]// X++[++[++[X][0]][0]][0]// X + 3
+ – Plus Sign
This symbol is useful, because it allows us to:
create numbers
add two values
concatenating strings
create strings
The current version of JSFuck uses it a lot but we not sure if they are fundamental.
Cast to Number
+[]// 0 - the number 0
Increment Numbers
Using the array wrapping trick mentioned above:
++[0][0]// 1++[[]][+[]]// 1
Getting undefined
Getting an element by index in an empty array will return undefined:
[][0]// undefined[][+[]]// get first element (undefined)[][[]]// look for property ""
Getting NaN
Casting undefined to Number will result in not-a-number:
请发表评论