Skip to content

Instantly share code, notes, and snippets.

@ShadowCreator250
Last active July 16, 2020 09:18
Show Gist options
  • Save ShadowCreator250/e1cd36b47c8c15af579e34b62fb44682 to your computer and use it in GitHub Desktop.
Save ShadowCreator250/e1cd36b47c8c15af579e34b62fb44682 to your computer and use it in GitHub Desktop.
A introduction to arrow functions in JS by Alan

https://discordapp.com/channels/392832386079129630/704005036732055723/706130765007683596

so, we have normal functions:

//regular function
function aNameForFunction(aparametertogive) {
  // run some code here.  
}; 

// arrow functions (also known as fat arrow syntax) 
const aNameForFunction = (parameter, moreparameter, ...) => {
  // run some code.  
}; 

Now... there are a few things we can do with arrow functions that are really powerful. If we have only 1 parameter, we don't need parentheses, like this:

const aFunction = aparameter => {
  // run some code.  
}

And finally, we have another thing we can do... if we only have 1 liners.. we can ignore the brackets too!

const aFunction = aparameter => console.log('This is a one liner implicit returned console log!'); 

// a more powerful example:  
const anArray = [1, 2, 3, 4, 5]; 
const aGoodFunction = anArray => anArray.forEach(itemInTheArray => console.log(itemInTheArray)); 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment