Types of function
- Normal function
- Arrow
- IIFE (pattern)
- Anonymous
Anonymous function
Anonymous means nameless - An function passed to forEach
_3[5, 6, 7].forEach(function (n) {_3 console.log(n * n);_3});
Normal function
_3function double(n) {_3 return n * 2;_3}
Arrow function
_3const double = (n) => {_3 return n * 2;_3};
If the function body is one line then no need of
return
{}
_1const double = (num) => num * 2;
Anonymous + Arrow function
_1[5, 6, 7].forEach((n) => console.log(n * n));
IIFE
_3(function double(n) {_3 console.log(n * 2);_3})(7);
IIFE + Anonymous
_3(function (n) {_3 console.log(n * 2);_3})(7);
IIFE + Anonymous + Arrow
_3((n) => {_3 console.log(n * 2);_3})(7);
@ragavkumarv
swipe to next โก๏ธ