js function shorthand code example
Example 1: arrow function rec
(param1, param2, …, paramN) => { statements }
(param1, param2, …, paramN) => expression
(singleParam) => { statements }
singleParam => { statements }
() => { statements }
Example 2: js arrow function
const add = (a, b) => a + b;
const square = num => {
return num * num;
}
const rollDie = () => (
Math.floor(Math.random() * 6) + 1
)
Example 3: arrow function in javascript
function PrintName(name){
console.log("my name is ", name) ;
}
const PrintName = (name) => {
return console.log("my name is " , name) ;
}
Example 4: arrow function javascript
const power = (base, exponent) => {
let result = 1;
for (let count = 0; count < exponent; count++) {
result *= base;
}
return result;
};
const square1 = (x) => { return x * x; };
const square2 = x => x * x;
const horn = () => {
console.log("Toot");
};