Skip to content

Instantly share code, notes, and snippets.

@toddzebert
Last active March 20, 2017 06:38
Show Gist options
  • Save toddzebert/f12569375bfead3e8954183c7748586d to your computer and use it in GitHub Desktop.
Save toddzebert/f12569375bfead3e8954183c7748586d to your computer and use it in GitHub Desktop.
Just a quick intro to JavaScript Arrow Functions to be used as an "aside" in a medium post

Arrow Functions aka => aka Fat Arrow aka Lambdas

It's a sugary anon function with some key differences. (params) => { code }

Syntax

  • No need for the function keyword
  • No need for {} if the function is only a single line
  • Single arguments (except rest args) don't need () but 0 args do
  • return is implicit with single line functions

vs Regular Functions

  • Lexical this - the most important; unlike a function, it does not define its own this value, it uses the enclosing context's this.
  • Lexical arguments - they share the arguments object of the enclosing scope. rest parameters can be used as an alternative.
  • They can't be used as generators or constructors; may have unexpected effects when used as methods; etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment