Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>at this point, i'd love to know when the answer is just '12'.

Ctrl+Shift+k in a browser (firefox) opens a console. Just write {}+12 there and hit enter.

My guess is that {} is (in some circumstances) evaluated as a block of code (instead of an empty object). Since the block is empty it evaluates to undefined. The +12 is considered another block of code ( the + operation takes here only one parameter - so it is not a sum ). Consecutive blocks of code are evaluated to the value of the last block of code, which is +12.

{}/12 for example doesn't work at all - which is a hint that the + is not a summation operation.

Edit: I'm wondering why we use 12 and not 42

Edit2: Technically you are correct about java being pass by value. But at this point I'm questioning the sanity of the distinction. It feels more and more like a philosophical discussion.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: