A Function in javascript is a collection of instructions that run when the function is invoked.
A normal function declaration in javascript is as declared as below:
function square(n){
return n*n;
}
// Then invoke it as :
console.log(square(5)); // 25
While the above is understood, functions can also be declared as Function expression
:
const square = function(n){
return n*n;
}
// Then invoke it as :
console.log(square(5)); // 25
There are many types of functions which I will cover in this 6 part series.
Different types of functions:
- Function declaration and Anonymous functions
- Arrow functions
- Methods
- Immediately invoked function expressions
- Callback functions
- Generator functions
Stay tuned for further posts.
Top comments (0)