Why do we use "const" declarator in declaration of functions in Javascript?
const functionName= () => {
...
}
const functionName = () => {
return 15;
}
Here an anonymous(lambda) function's result is assigning to a constant variable 'functionName'. Just like const x = 5;
Lambda functions are used when you need a function for a short period of time. It has no function name. This is commonly used when you want to pass a function as an argument to higher-order functions, that is, functions that take other functions as their arguments.
// Function declaration
function add(){
}
// A variable declared
const add=()=>{
}
Function promotion occurs in function declarations,Variable declarations are not promoted