It Ain't Over Until the Fat Arrow => Sings...

I know what you’re thinking: “What a terribly chosen blog title for SEO…”. At least, that’s what I thought when I first wrote it… //I digress

Anyways. I was soooo confused on understanding arrow functions. I didn’t even know they were defining functions! I wish Google did a better job at returning relevant results when searching for “javascript =>”.

I just wanted to reference this handy post by StrongLoop: “An Introduction to JavaScript ES6 Arrow Functions” (Now that’s a great SEO title…)

Arrow functions serve two main purposes:

  • more concise syntax
  • sharing lexical this with the parent scope

Here’s an example of how a function can be written using arrow notation:

function () { return 1; } () => 1

I also appreciated the summary from that article:

It might be very tempting to just start using => instead of function everywhere. I’ve seen whole libraries written just using => and I don’t think it’s the right thing to do because of the special features that => introduces. I recommend using arrow functions only in places where you explicitly want to use the new features:

  • Single statement functions that immediately return (lambdas)
  • Functions that need to work with parent scope this

Intrigued? Read: “An Introduction to JavaScript ES6 Arrow Functions”

Duncan Leung

Front End Developer at iHerb.com

Irvine, CA

Subscribe to Duncan Leung: Javascript and Front End Development

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!