Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverted parentheses in Javascript [duplicate]

What is it about Javascript that lets me use inverted / backwards parentheses in function calls like this? I'm running in a Node console on the CLI; specifically Node version 0.10.25.

function a(){ return 42 } a() // -> 42 a)( // -> 42.  WTF?  function b(t){ return t } b(4) // -> 4 b)4( // No function evaluation; presumably dangling parentheses b)(4 // -> 4.  WTF? 

Addendum: This doesn't appear to work in Chrome 33.0.1750.152, Safari 7.0.2, or Firefox 27.01. Is this actually some kind of "feature" of some interpretation of ECMAScript, or a Node peculiarity? If Node is using V8, shouldn't it match up with the Chrome results?

like image 960
Bryce Avatar asked Mar 20 '14 17:03

Bryce


1 Answers

It is possible that the console wraps everything inside an eval statement: what is actually evaluated is maybe eval(a)(). In that case Chrome returns 42 as well.

like image 72
fabiolune Avatar answered Sep 26 '22 21:09

fabiolune