single line function javascript code example

Example 1: javascript oneline function

const sum = (x, y) => x + y;

Example 2: 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 3: javascript 1 line if

(lemons) ? alert("please give me a lemonade") : alert("then give me a beer");

Example 4: 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