DEV Community

Discussion on: UNDERSTANDING FIRST-CLASS FUNCTIONS AND ANONYMOUS FUNCTIONS IN JAVASCRIPT

Collapse
 
crs1138 profile image
Honza • Edited

Is this a typo?

const anonymousAgeTeller = (age){
    console.log(`my age is ${age}`);
}

This produces an error: Uncaught SyntaxError: Unexpected token '{'

Did you mean:

const anonymousAgeTeller = function(age){
    console.log(`my age is ${age}`);
}

I'm sorry to be nitpicking but…

2 + 2
// this is an arithmetic expression, 
// the + sign in this context is an arithmetic operator
// not a function. Try console.dir(+), you get an error.

Collapse
 
lawrence_eagles profile image
Lawrence Eagles • Edited

Hello Honza, thanks for your observation.

const anonymousAgeTeller = (age){
    console.log(`my age is ${age}`);
}

This is actually a typo which I have corrected. Thanks again.

However in regards to the expression:

2 + 2

This is actually an arithmetic expression no doubt and as understand it, the addition operator is a special function that uses the infix notation and returns the value of adding its two operands.
So it is a function.
I did not fully understand you here.

Collapse
 
crs1138 profile image
Honza

Hi Lawrence,
first of all, I'd like to thank you for the article. I think it's brilliant! And thanks for getting back to me this quickly and fixing the typo.

I'll elaborate a bit on the + operator. What I meant, it's not a Function object. The compiler likely works with it as an infix function, but strictly speaking, it is not a Javascript function as such. I just believe that the example adds unnecessary confusion to the topic.

Thread Thread
 
lawrence_eagles profile image
Lawrence Eagles

Hello, Honza,
Now I understand you better. I have removed those ambiguous sections of the article.
Thanks for helping improve the quality, you are appreciated.

Thread Thread
 
crs1138 profile image
Honza

Thank you for sharing your insight with the community. I really appreciate your effort.