DEV Community

Cover image for Functions in javascript
Buddhadeb Chhetri
Buddhadeb Chhetri

Posted on • Edited on

3

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

Sentry blog image

Identify what makes your TTFB high so you can fix it

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

Read more

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✌

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay