What is Functions?
Fundamental building blocks of all programming.
Reusable block of code designed to perform a particular task.
Functions are executed when they are called.
Example
function greet(){
return "Hello";
}
console.log(greet());
Function Expression
A function stored inside a variable.
Function may or may not have a name.If the function doesn't have a name,then it is called anonymous function.
If the function is anonymous, the variable name acts as its function name.
Example
const display = function(num){
console.log(num);
}
Arrow Function
- Arrow Functions allow a shorter syntax for function expressions.
const add = (a,b)=>{
return a+b;
}
console.log(add(2,3));
Top comments (0)