DEV Community

Discussion on: All you need to know about Javascript's Expressions, Statements and Expression Statements

Collapse
 
dudleycraig profile image
Dudley Craig • Edited

this article looked to be answering some queries i've had, tho got stopped at this ...
const foo = foo () => {
assignedVariable = 14
}
what does that mean? it doesn't compile ... is it an attempt to be a "named expression"? I'd assumed the arrow syntax is only for anonymous expressions?

again here, what's this? ... "foo(function () {} );"?

a bit ambiguous for me.

Collapse
 
paxfeline profile image
David Newberry

The code has one too many "foo"s, it should be:

const foo = () => {
assignedVariable = 14
}

() => { ... } is an anonymous function, which is then assigned to const foo.

The other code:
foo(function () {} );
also uses an anonymous function (using different syntax). This code would mean call the function "foo" and pass an anonymous (and empty) function.