Skip to content

Instantly share code, notes, and snippets.

@tararoutray
Last active September 2, 2021 10:36
Show Gist options
  • Save tararoutray/10b84c1fe3e074b5186221e60f5b3f61 to your computer and use it in GitHub Desktop.
Save tararoutray/10b84c1fe3e074b5186221e60f5b3f61 to your computer and use it in GitHub Desktop.
// This is a regular function
function addTwoNumbers(x, y) {
return (x + y);
}
// This is an arrow function
// There's an important syntactical difference to note:
// The arrow functions use the => instead of the "function" keyword.
const addTwoNumbers = (x, y) => x + y;
// Writing a multi-line arrow function
const isEven = (number) => {
return (number % 2 == 0) ? true : false;
}
// Some arrow functions have parentheses around the parameters and others don't.
// With parentheses
const substractNumbers = (x, y) => x - y;
// Without parentheses
const squareNumber = x => x^2;
// An arrow function with no parameters needs parentheses.
const sayHi = () => alert('Hey There!');
// An arrow function with only one parameter does not need parentheses.
const squareNumber = x => x^2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment