DEV Community

Discussion on: JavaScript Functions: Explain Like I'm Five

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Regarding function expressions, you've omitted to mention that you can name functions defined in this manner - and in fact it can be a good idea to do so. If they are not named they will show up as 'anonymous' functions in stack traces. So, it is equally valid to write:

const calcAge2 = function calculateAge(birthyear) {
    return 2021 - birthyear;
}
Enter fullscreen mode Exit fullscreen mode

In this case, stack traces involving the function will show the name calculateAge instead of 'anonymous function'

Collapse
 
sumusiriwardana profile image
Sumudu Siriwardana • Edited

Thank you so much for correcting that, Jon! I will add that part.

Just wanted to show the difference as basics without confusing the newbies, because I was not touching other function types in this article. 😂

Collapse
 
peerreynders profile image
peerreynders

I don't disagree with your premise in the least - I prefer explicitly named functions as well.

However introduced with ES2015: