Functions:-Functions in JavaScript provide organized, reusable code to perform a set of actions. Functions simplify the coding
process, prevent redundant logic, and make code easier to follow.
1.Named Function
function myfunction(){
console.log('Budddhadeb Chhetri');
}
myFunction(); //Prints: Buddhadeb Chhetri
2.Named Function with arguments
function myFunction(parameter){
console.log('parameter');
}
myFunction(10); //Prints:10
3.Anonymous function
const myFunction =function(){
console.log('Buddhadeb Chhetri');
}
myFunction(); //Prints: Buddhadeb Chhetri
4.Anonymous function with arguments
const myFunction = function(parameter){
console.log (parameter);
}
myFunction(10); //Prints: 10
5.Arrow function with no argument
const myFunction = ()=>{
console.log ('Buddhadeb');
}
myFunction(); //Prints: Buddhadeb
6.Arrow function with a single argument
const myFunction = parameter()=>{
console.log (parameter);
}
myFunction(20); //Prints: 20
7.Arrow function with a two arguments
const mysum = (param1,param2)=>{
console.log (param1+param2);
}
myFunction(2,5); //Prints: 7
8.Concise arrow funtion with arguments
const mySum = (a,b)=>a+b;
console.log (2,5); //Prints: 7
Top comments (2)
Number 6 arrow function:
const myFunction = parameter => {
console.log (parameter) ;
}
Thanks for the correction✌