DEV Community

Cover image for Functions in javascript
Buddhadeb Chhetri
Buddhadeb Chhetri

Posted on • Updated on

Functions in javascript

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
Enter fullscreen mode Exit fullscreen mode

2.Named Function with arguments

function myFunction(parameter){ 
   console.log('parameter');                                                       
  }
myFunction(10); //Prints:10
Enter fullscreen mode Exit fullscreen mode

3.Anonymous function

const myFunction =function(){
   console.log('Buddhadeb Chhetri');
}
myFunction(); //Prints: Buddhadeb Chhetri
Enter fullscreen mode Exit fullscreen mode

4.Anonymous function with arguments

const myFunction = function(parameter){
  console.log (parameter);
}
myFunction(10); //Prints: 10
Enter fullscreen mode Exit fullscreen mode

5.Arrow function with no argument

const myFunction = ()=>{
  console.log ('Buddhadeb');
}
myFunction(); //Prints: Buddhadeb
Enter fullscreen mode Exit fullscreen mode

6.Arrow function with a single argument

const myFunction = parameter()=>{
  console.log (parameter);
}
myFunction(20); //Prints: 20
Enter fullscreen mode Exit fullscreen mode

7.Arrow function with a two arguments

const mysum = (param1,param2)=>{
  console.log (param1+param2);
}
myFunction(2,5); //Prints: 7
Enter fullscreen mode Exit fullscreen mode

8.Concise arrow funtion with arguments

const mySum = (a,b)=>a+b;
console.log (2,5); //Prints: 7
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
stormkid2009 profile image
Anwar Ahmed

Number 6 arrow function:
const myFunction = parameter => {
console.log (parameter) ;
}

Collapse
 
buddhadebchhetri profile image
Buddhadeb Chhetri

Thanks for the correction✌