Building JavaScript from Six Characters: A jsFuck Tutorial

This article explains how JavaScript’s type coercion rules can be exploited to construct any string or code using only the characters []()+! and demonstrates step‑by‑step how to build letters, functions, and even execute code, illustrating the principles behind the jsFuck obfuscation technique.

Beike Product & Technology
Beike Product & Technology
Beike Product & Technology
Building JavaScript from Six Characters: A jsFuck Tutorial

JavaScript’s flexible type conversion allows strings, numbers, booleans, and objects to be created from the minimal character set []()+!, which the article calls the "golden rules": ! yields a Boolean, + yields a Number, and []+[] yields a String.

By combining these rules, simple expressions such as ![]===false, +[]===0, and []+[]==="" are shown, then extended to extract characters from built‑in strings like (![]+[])[+!![]]==="a" and to build words such as fill, filter, and find using array method names.

The article demonstrates how to retrieve additional letters via constructor functions, e.g.,

true["constructor"]+[]==="function Boolean() { [native code] }"

, and how to assemble the full alphabet by converting numbers to different bases with (12)["toString"](16)==="c".

It then shows how to obtain punctuation and HTML tags using string methods like "test"["bold"]() which returns <b>test</b>, and how to invoke the global escape function via

[]["fill"]["constructor"]("return escape(' ')")()==="%20"

.

Finally, the article explains constructing and executing arbitrary code with the Function constructor, for example Function("alert('test')")();, and concludes that using only []()+!. one can achieve Turing‑complete JavaScript, as demonstrated by the jsFuck project.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

code obfuscationJSFuckType Coercion
Beike Product & Technology
Written by

Beike Product & Technology

As Beike's official product and technology account, we are committed to building a platform for sharing Beike's product and technology insights, targeting internet/O2O developers and product professionals. We share high-quality original articles, tech salon events, and recruitment information weekly. Welcome to follow us.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.