1// The usual way of writing function
2const magic = function() {
3 return new Date();
4};
5
6// Arrow function syntax is used to rewrite the function
7const magic = () => {
8 return new Date();
9};
10//or
11const magic = () => new Date();
12
13
1const plantNeedsWater = day => day === 'Wednesday' ? true : false;
2
3//If only 1 Parameter no () needed
4//Single line return is implicit
5//Single line no {} needed
1const power = (base, exponent) => {
2 let result = 1;
3 for (let count = 0; count < exponent; count++) {
4 result *= base;
5 }
6 return result;
7};
8
9//if the function got only one parameter
10
11const square1 = (x) => { return x * x; };
12const square2 = x => x * x;
13
14// empty parameter
15
16const horn = () => {
17 console.log("Toot");
18};