Live data from Hacker News

JSFuck – esoteric JavaScript

jsfuck.com

21–30 of 39 posts

Re: JSFuck – esoteric JavaScript

#21

For those wondering how you get numbers, strings and other primitives from a whole bunch of empty arrays and objects in JavaScript, here's what happens when you do arithmetic and other operations on arrays and objects: > [] + [] "" (An empty string) > {} + [] 0 (The number zero) > [] + {} "[object Object]" (.toString() called on a plain object). > ![] false (!{} is the same) > !![] true (not false) > +[] 0 (the numbe…

Does knowing any of this make you a better programmer? I'd say no. Should you be using any of this in production code? No The next programmer even if he is a really good one might not know that particular esoteric trick. I'm not trying to vote down or anything, but what is the point? Most of it look like language design warts to me. Most of them should have thrown exceptions and errored out. Now I'm loving the idea o…

Most of it is warts and is completely useless. Sometimes things like knowing that an array is an abject are pretty important if you're writing production code.

The bit at the end (integer and float casting) is almost essential knowledge now for anyone writing JavaScript code that does anything mildly intensive.

Re: JSFuck – esoteric JavaScript

#22

Earlier quoted context omitted.

Does knowing any of this make you a better programmer? I'd say no. Should you be using any of this in production code? No The next programmer even if he is a really good one might not know that particular esoteric trick. I'm not trying to vote down or anything, but what is the point? Most of it look like language design warts to me. Most of them should have thrown exceptions and errored out. Now I'm loving the idea o…

Useful for obfuscating executable JS for security reasons.

It'd have to be something that really had to be hidden, because most of these edge cases are very very slow to run.

Re: JSFuck – esoteric JavaScript

#23

Earlier quoted context omitted.

Does knowing any of this make you a better programmer? I'd say no. Should you be using any of this in production code? No The next programmer even if he is a really good one might not know that particular esoteric trick. I'm not trying to vote down or anything, but what is the point? Most of it look like language design warts to me. Most of them should have thrown exceptions and errored out. Now I'm loving the idea o…

Useful for obfuscating executable JS for security reasons.

Why? I believe you have more sophisticated ways of obfuscating code. Those tricks seem to be easy to reverse.

Re: JSFuck – esoteric JavaScript

#27

For those wondering how you get numbers, strings and other primitives from a whole bunch of empty arrays and objects in JavaScript, here's what happens when you do arithmetic and other operations on arrays and objects: > [] + [] "" (An empty string) > {} + [] 0 (The number zero) > [] + {} "[object Object]" (.toString() called on a plain object). > ![] false (!{} is the same) > !![] true (not false) > +[] 0 (the numbe…

Does knowing any of this make you a better programmer? I'd say no. Should you be using any of this in production code? No The next programmer even if he is a really good one might not know that particular esoteric trick. I'm not trying to vote down or anything, but what is the point? Most of it look like language design warts to me. Most of them should have thrown exceptions and errored out. Now I'm loving the idea o…

The problem is the strong-typing/weak-typing distinction, not the static-typing/dynamic-typing distinction. For example, Python is about as strongly typed as C++ yet they're on opposite sides wrt. how dynamic their types are.

Re: JSFuck – esoteric JavaScript

#28

For those wondering how you get numbers, strings and other primitives from a whole bunch of empty arrays and objects in JavaScript, here's what happens when you do arithmetic and other operations on arrays and objects: > [] + [] "" (An empty string) > {} + [] 0 (The number zero) > [] + {} "[object Object]" (.toString() called on a plain object). > ![] false (!{} is the same) > !![] true (not false) > +[] 0 (the numbe…

Does knowing any of this make you a better programmer? I'd say no. Should you be using any of this in production code? No The next programmer even if he is a really good one might not know that particular esoteric trick. I'm not trying to vote down or anything, but what is the point? Most of it look like language design warts to me. Most of them should have thrown exceptions and errored out. Now I'm loving the idea o…

> Does knowing any of this make you a better programmer? I'd say no.

Yes it does, it makes sure you never do this ;P

Adding arrays sounds like something I'd totally try in JS, had I not known that it causes magic unicorn sparkles to happen)

Re: JSFuck – esoteric JavaScript

#30
post #10

I know this will most likely come as a surprise to most Javascript programmers but all code is represented using only two "characters" deep inside your little computers!

What do you mean two characters? What are they exactly? I'm guessing $ and ; because it's like jQuery but some operations seem impossible, like how does it even assign variables?
Post reply on HN