js arrow function pass arguments code example

Example 1: arrow function rec

(param1, param2,, paramN) => { statements } 
(param1, param2,, paramN) => expression
// equivalent to: => { return expression; }

// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }

// The parameter list for a function with no parameters should be written with a pair of parentheses.
() => { statements }

Example 2: arrow function javascript

const power = (base, exponent) => {
  let result = 1;
  for (let count = 0; count < exponent; count++) {
    result *= base;
  }
  return result;
};

//if the function got only one parameter

const square1 = (x) => { return x * x; };
const square2 = x => x * x;

// empty parameter

const horn = () => {
  console.log("Toot");
};

Example 3: concise body arrow functions javascript

const plantNeedsWater = day => day === 'Wednesday' ? true : false;

//If only 1 Parameter no () needed
//Single line return is implicit
//Single line no {} needed