DEV Community

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

Posted on

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.