What are Functions ?• Functions are the fundamental building block for structuring and executing code in JavaScript applications.
• Functions allows you to encapsulate a set of operations, improve code reusability.
Function Declaration
Defines a function with a name. The function can be called before its definition because of its hoisting behavior.
Hoisting is a javascript behaviour that transfer the declaration of function, variable declaration using varto the top of its scope.
function function_name(arguments){
}
function_name(arguments)
function sum(a,b){
console.log(a + b)
}
sum(20,10)
Function Expression
Defines a function as an expression. This approach is not hoisted, so the function must be defined before it can be used.
const fun = function (a,b){
return a * b
}
fun(20,10)
Arrow function
A shorter syntax introduced in ES6. Arrow functions have lexical this binding and are often used for shorter inline functions.
const fun = (a,b) => {
return a + b
}
const fun2 = (a,b) => a+b
If you want more such content then make sure to following me on all available platform
Instagram
LinkedIn
Hashnode
Thank you for reading 🤍
Written By Mohit Soni
Source: hashnode.com