What is () => ?

91 views
Skip to first unread message

Ömer

unread,
Jul 2, 2016, 9:38:58 PM7/2/16
to nodejs
What is the () => sign ? I see it on examples. Is it used for only pseudo-code purposes or is it used in code? What it means? I cannot search it on google. 
maybeSync(true, () => {       
     foo();     
});     
bar(); 

Thanks in advance..

Scott González

unread,
Jul 2, 2016, 10:05:09 PM7/2/16
to nod...@googlegroups.com
That's an arrow function. You can read about it on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/cf4a6847-73b3-4ed8-9ff0-b160d574db72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Miike Ramos

unread,
Jul 2, 2016, 10:05:09 PM7/2/16
to nod...@googlegroups.com
Hi. () => {} is shorthand for:

function() {
 ...
}

It's syntax you will see in ECMAScript 6. You can learn more about the new syntax at https://babeljs.io/ and start writing the future of JavaScript today!


--

Joshua Holbrook

unread,
Jul 3, 2016, 12:35:48 AM7/3/16
to nod...@googlegroups.com
> Hi. () => {} is shorthand for:

Possibly being pedantic, but I think it's important to point out that
there are significant and relevant differences in behavior wrt the
'this' keyword (meaning it's not strictly a shorthand). The MDN
article speaks to this. (heh. this.)

--Josh
> https://groups.google.com/d/msgid/nodejs/CALPwyBTt%3DV2-jKOYsnf0%2BjPyaewqYNDX82Nx%2Bohvypfn%2BUupSQ%40mail.gmail.com.

jerome

unread,
Jul 4, 2016, 12:21:01 AM7/4/16
to nodejs
Also worth taking note of the optional implicit return value afforded by "fat arrow functions".

e.g.

(data) => data

That kind of thing.
Reply all
Reply to author
Forward
0 new messages