DEV Community

Cover image for Javascript Developers should know these ways of defining functions
kidd-creator
kidd-creator

Posted on

4 1

Javascript Developers should know these ways of defining functions

THIS IS AN ARROW FUNCTIONS

const myfunction = () =>  console.log("function called");
Enter fullscreen mode Exit fullscreen mode

OR

const myfunction = () =>  {
    console.log("function called");
    return "anything";
}
Enter fullscreen mode Exit fullscreen mode

THIS FUNCTION CALLS ITSELF

(function myfuntion(){
    console.log("function called");
})()
Enter fullscreen mode Exit fullscreen mode

NESTED FUNCTIONS

function outter(){
    function inner1(){
       //code
    }
}
Enter fullscreen mode Exit fullscreen mode

I'm actually a javascript newbie (started a month ago)
So if there's a mistake please tell me.

Top comments (1)

Collapse
 
tohka200213 profile image
tohka20-0213 • Edited

Thanks.

The other is the Function expression.

const myfuntion = function() {
  console.log("Yfunction called");
};
Enter fullscreen mode Exit fullscreen mode

However, I often use an arrow function instead of the above.

Sentry mobile image

Improving mobile performance, from slow screens to app start time

Based on our experience working with thousands of mobile developer teams, we developed a mobile monitoring maturity curve.

Read more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay