5 ms·
Writing JavaScript with Only Six Characters
- ewendel 7y agoI don't write alot of blog posts. Appreciate any feedback you might have :)
- getcrunk 7y agoIt’s great my guy! Love the recap at the end
- Waterluvian 7y agoI love it. But I think it cheats a tiny bit by getting a word that requires only characters from "false". It means you're demonstrating the same trick four times. Maybe you could do a kind of proof: 1. This is how you get any character 2. This is how you call eval() 3. QED
- herohamp 7y agoYeah the ability to get any character would really show more of how this works
- trehalose 7y agoPlease run simple code to verify accuracy before publishing it. The unary plus operator coerces undefined to NaN, not to zero as your article states. The unary plus operator coerces NaN to NaN, not to zero as your article states. (Remember that NaN is already a number, despite its name.) If you need to coerce any falsy value to 0, the simplest way is to use bitwise operators. If you want to do it the six character way, I guess use Math.imul
- sveingjoby 7y agoGreat article. I've seen articles about this concept before, but none of these had such a thorough explanation!
- matsemann 7y agoIs there a limit to what one can do with these six characters? Like, now we're reading values from the string "false". We also could read from "true", and maybe undefined (how?). But can one do more? If one can generate "window", one should be able to call functions through window["functionName"]() and do general computing with this, I think?
- maury91 7y agoyou can obtain undefined by accessing the first element of an empty array. `([])[+!![]]`
- ewendel 7y agoAs I understand, there's no limit to what you can do with these six characters. It quickly gets more complicated though, and will require alot more code: "undefined": [][![]]+[] (empty array accessed at index 0 turned into string) "NaN": +{} "[object Object][object Object]": {}+{} .. etc See the full list here: https://github.com/aemkei/jsfuck/blob/master/jsfuck.js https://github.com/aemkei/jsfuck/blob/master/jsfuck.js
- nchntrz 7y agoPretty good explanation. For those who want to dive deeper, there is an esoteric language based on these concepts: http://www.jsfuck.com/ http://www.jsfuck.com/
- maury91 7y agoyou can make the final code slightly shorter by obtaining the "e" from "true" instead of "false". `(!![]+[])[+!+[]+!+[]+!+[]]`
- 74ls00 7y agoWorld’s most unreadable embedded programming language?
- rsiqueira 7y agoThere's Dwitter, a minimalist JavaScript code community, where we use these kind of tricks to write interesting code, demos and concepts with just 140 characters or less: https://dwitter.net/ https://dwitter.net/
- giancarlostoro 7y agoThis is fascinating! Thanks for the share, I had no idea this even existed. Some of the posts are impressive too. Walther is known for their short reset triggers on their handguns for example.
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- rsiqueira 7y agoI've just posted a working code on Dwitter based on this "JavaScript with Only Six Characters", it shows 1e+100 turning into Infinity. https://www.dwitter.net/d/16881 https://www.dwitter.net/d/16881