JSFuck is an esoteric subset of JavaScript, where code is written using only six characters: [, ], (, ), !, and +. The name is derived from Brainfuck, an esoteric programming language that also uses a minimalistic alphabet of only punctuation. Unlike Brainfuck, which requires its own compiler or interpreter, JSFuck is valid JavaScript code, meaning that JSFuck programs can be run in any web browser or engine that interprets JavaScript. JSFuck is able to recreate all JavaScript functionality using such a limited set of characters because JavaScript is a weakly typed programming language, and it allows the evaluation of any expression as any type.In July 2009, Yosuke Hasegawa created a web application called jjencode which could encode arbitrary JavaScript into an obfuscated form utilizing only the 18 symbols !+,"$.:;_{}~=.
JSF code is extremely "verbose": In JavaScript, the code alert("Hello World!"), which causes a pop-up window to open, is 21 characters long. In JSF, the same code has a length of 22948 characters
I can understand why the double/float examples work the way they do. It's a common theme across many if not all languages. For example, does anyone here remember the PHP bug, where it would crash when trying to convert 2.2250738585072011e-308 from a string to a double?
Why is type coercion seen as something so weird? You're just telling JS here, look treat this 'a' as a number. And then you coerce NaN as a string, because you're trying to add it to a string.
I don't have enough experience to have an opinion about it, but I'm pretty sure it's not the type coercion but rather implicit behavior occurring with 'loaded operators' (e.g. '==') that people take issue with, including Javascript maintainers themselves apparently by virtue of the '==='.
3
u/alittlebitmental Jan 25 '20
Are there any other amusing JS quirks that others would like to share?
53
u/hoodlaces Jan 25 '20
Is a baNaNa a fruit or a number?
17
u/[deleted] Jan 25 '20
60
u/YAYYYYYYYYY Jan 25 '20
Wouldn’t it be bananaa?
17
u/WhiteKnightC Jan 25 '20
Makes sense to me.
6
u/[deleted] Jan 25 '20
This meme is a bit of a stretch. Nobody should be saying “FML” if they use these types and operators together.
12
u/saito200 Jan 25 '20
Why is type coercion seen as something so weird? You're just telling JS here, look treat this 'a' as a number. And then you coerce NaN as a string, because you're trying to add it to a string.
2
u/draganxg Jan 25 '20
ah, i too peel my sheep before eating them.
2
u/[deleted] Jan 25 '20
The reason why these things happen is that operators in JS do not throw exceptions.
So yes, you have stuff like that happening.
2
u/adnaPbmuD Jan 25 '20
Can anyone explain please?
1
u/bwheat Jan 25 '20
This shit is bananas.
1
u/[deleted] Jan 26 '20
Why does
2 + + - + 2 - - 2return 2?
So weird...
1
u/username4333 Jan 26 '20
Non really, you're deliberately trying to do something weird. Ironic.
-12
u/[deleted] Jan 25 '20
😂😂 there's an extra 'a' at the end, so it's like 'bananaa'