Skip to content

Instantly share code, notes, and snippets.

@mowat27
Created March 6, 2017 20:33
Show Gist options
  • Save mowat27/9ecc8388c822f35e1792b8758dffc515 to your computer and use it in GitHub Desktop.
Save mowat27/9ecc8388c822f35e1792b8758dffc515 to your computer and use it in GitHub Desktop.
Example of why ES6 is cool
// Converting an ES5 function ES6
// Start
function getWords(text) {
return text.split(/\s/)
}
// Use const declaration
const getWords = function(text) {
return text.split(/\s/)
}
// Convert to fat arrow
const getWords = (text) => {
return text.split(/\s/)
}
// Use round brackets
const getWords = (text) => (
return text.split(/\s/)
)
// return is now implicit
const getWords = (text) => (
text.split(/\s/)
)
// But we don't need brackets for a one liner
const getWords = (text) => text.split(/\s/)
// ... or parens in the args list
const getWords = text => text.split(/\s/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment