Skip to content

Instantly share code, notes, and snippets.

@vmarchesin
Created September 11, 2018 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmarchesin/df50cb8692918557379b54aa03cd3e05 to your computer and use it in GitHub Desktop.
Save vmarchesin/df50cb8692918557379b54aa03cd3e05 to your computer and use it in GitHub Desktop.
Javascript Arrow Functions and Closure
const movies = [
{ rating: 8.4, title: 'The Shining' },
{ rating: 8.3, title: 'Reservoir Dogs' },
{ rating: 6.2, title: 'Alien vs Predator' }
]
// Using the function keyword
movies.sort(function (a, b) {
return a.rating - b.rating
})
// Using the arrow function syntax
movies.sort((a, b) => a.rating - b.rating)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment