gitmyhub

jsfuck

JavaScript ★ 8.6k updated 1y ago

Write any JavaScript with 6 Characters: []()!+

A JavaScript curiosity that proves any program can be written using only six characters, an educational experiment revealing how JavaScript silently converts between types.

JavaScriptsetup: easycomplexity 1/5

JSFuck is an experiment that proves you can write any JavaScript program using only six characters: [, ], (, ), !, and +. The result looks nothing like normal code. A simple alert(1) turns into dozens of lines of brackets and plus signs. Despite looking like noise, it executes correctly in any standard JavaScript environment, including browsers and Node.js.

The project works by exploiting how JavaScript handles type conversions. JavaScript freely converts between numbers, strings, booleans, and arrays depending on context. For example, an empty array [] treated as a number becomes zero, and treated as a string becomes an empty string. By carefully combining these coercions with the handful of allowed characters, you can build any digit, any letter, and eventually any string or function call. The README walks through each step: how to get the number 1, how to get the word undefined, how to extract individual characters from that word, and how to eventually build method names like filter or constructor that let you run arbitrary code.

This is described as an esoteric and educational project. Esoteric means it is intentionally impractical, more of a curiosity or puzzle than something you would use in real software. Educational means studying it reveals real things about how JavaScript's type system works under the hood, which is why it has attracted attention from developers curious about language internals.

The library includes a conversion function so you can input any JavaScript code and get the JSFuck equivalent out. A live demo is available at jsfuck.com. The README is detailed, explaining the logic behind each character and each step in building up from simple values to complete programs.

Where it fits