Blog

Function

JS

Types of function

Types of function in JS

Ragav Kumar V

Ragav Kumar V

Aug 20, 2022 ยท 1 min read

  1. Normal function
  2. Arrow
  3. IIFE (pattern)
  4. Anonymous

Anonymous means nameless - An function passed to forEach


_3
[5, 6, 7].forEach(function (n) {
_3
console.log(n * n);
_3
});


_3
function double(n) {
_3
return n * 2;
_3
}


_3
const double = (n) => {
_3
return n * 2;
_3
};

  1. return
  2. {}

_1
const double = (num) => num * 2;


_1
[5, 6, 7].forEach((n) => console.log(n * n));


_3
(function double(n) {
_3
console.log(n * 2);
_3
})(7);


_3
(function (n) {
_3
console.log(n * 2);
_3
})(7);


_3
((n) => {
_3
console.log(n * 2);
_3
})(7);

@ragavkumarv
swipe to next โžก๏ธ